SlideShare ist ein Scribd-Unternehmen logo
1 von 21
PERFORMANTE 
JAVA ENTERPRISE APPLIKATIONEN 
TROTZ O/R-MAPPING 
Simon Martinelli, simas GmbH 
@simas_ch | about.me/simas_ch 
https://github.com/simasch/orders
DAS PROBLEM
DAS MODELL
N+1 SELECT PROBLEM 
• Orders und OrderItems = FetchType.LAZY 
@OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, orphanRemoval = 
true) 
private Set<Order> orders; 
@OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true) 
private List<OrderItem> items; 
• Ein Query für alle Customers 
• Pro Customer 1 Query für die Orders 
• Pro Order 1 Query für die OrderItems
LÖSUNGSANSÄTZE 
• FetchType.EAGER oder EntityGraph (JPA 2.1) 
– Nur ein Hinweis für JPA 
– != SQL JOIN 
– Hibernate erlaubt nur eine List mit 
FetchType.EAGER pro Entity 
org.hibernate.HibernateException: cannot simultaneously fetch 
multiple bags 
• JOIN FETCH 
– Achtung vor kartesischen Produkten
DTO 
Quelle: Martin Fowler, http://martinfowler.com/eaaCatalog/dataTransferObject.html
CustomerInfoDTO 
public class CustomerInfoDTO { 
private final Long id; 
private final String lastname; 
private final String firstname; 
private final double revenue; 
public CustomerInfoDTO(Long id, String lastname, String firstname, 
double revenue) { 
this.id = id; 
this.lastname = lastname; 
this.firstname = firstname; 
this.revenue = revenue; 
} 
...
CONSTRUCTOR EXPRESSION 
Query q = em.createQuery( 
"SELECT " + 
"NEW control.CustomerInfoDTO(c.id, c.lastname, c.firstname," + 
"SUM(i.product.price)) " + 
"FROM Customer c " + 
"JOIN c.orders o " + 
"JOIN o.items i " + 
"GROUP BY c.lastnamem, c.firstname" + 
"ORDER BY c.lastname, c.firstname"); 
List<CustomerInfoDTO> list = q.getResultList();
DAS DATENMODELL IM ZENTRUM 
• Ein 1-1 Abbild der Datenbank in Entities oft 
unnötig 
X
WAS IST MIT JPQL OHNE DIE 
BEZIEHUNG CUSTOMER->ORDER? 
NEU IN JPA 2.1 
Query q = em.createQuery( 
"SELECT " + 
"NEW control.CustomerInfoDTO(c.id, c.lastname, c.firstname, " + 
"SUM(i.product.price)) " + 
"FROM Customer c " + 
"JOIN c.orders o ON o.customerId = c.id " + 
"JOIN o.items i " + 
"GROUP BY c.lastname, c.firstname" + 
"ORDER BY c.lastname, c.firstname"); 
List<CustomerInfoDTO> list = q.getResultList();
ORM FÜR ALLES? 
Just because you're using Hibernate, doesn't 
mean you have to use it for everything. 
A point I've been making for about ten years 
now. 
Gavin King, 10.12.2013
SQL? 
• VORTEILE 
– Testbar mit SQL Developer/TOAD/IDE 
– Optimierbar (Execution Plan) 
• ABER SQL VON HAND? NEIN! 
– JPA 2.1 ConstructorResult 
– QLRM 
– jOOQ
JPA 2.1 CONSTRUCTOR RESULT 
Query q = em.createNativeQuery( 
"SELECT C.ID, C.LASTNAME, C.FIRSTNAME, SUM(P.PRICE) AS REVENUE" + 
"FROM CUSTOMERS C " + 
"JOIN ORDERS O ON O.CUSTOMER_ID = C.ID " + 
"JOIN ORDERITEMS I ON I.ORDER_ID = O.ID " + 
"JOIN PRODUCTS P ON P.ID = I.PRODUCT_ID " + 
"GROUP BY C.ID, C.LASTNAME, C.FIRSTNAME " + 
"ORDER BY C.LASTNAME, C.FIRSTNAME", "CustomerInfoDTO"); 
@SqlResultSetMapping(name="CustomerInfoDTO", 
classes={ 
@ConstructorResult(targetClass=CustomerInfoDTO.class, 
columns={@ColumnResult(name="ID"), 
@ColumnResult(name="LASTNAME"), 
@ColumnResult(name="FIRSTNAME"), 
@ColumnResult(name="REVENUE", type=Double.class)}) 
})
QLRM 
Query q = em.createNativeQuery( 
"SELECT C.ID, C.LASTNAME, C.FIRSTNAME, SUM(P.PRICE) AS REVENUE" + 
"FROM CUSTOMERS C " + 
"JOIN ORDERS O ON O.CUSTOMER_ID = C.ID " + 
"JOIN ORDERITEMS I ON I.ORDER_ID = O.ID " + 
"JOIN PRODUCTS P ON P.ID = I.PRODUCT_ID " + 
"GROUP BY C.ID, C.LASTNAME, C.FIRSTNAME " + 
"ORDER BY C.LASTNAME, C.FIRSTNAME"); 
JpaResultMapper mapper = new JpaResultMapper(); 
List<CustomerInfoDTO> list = 
jpaResultMapper.list(q, CustomerInfoDTO.class); 
QLRM: https://github.com/simasch/qlrm
jOOQ 
List<CustomersInfoDTO> list = create. 
select(CUSTOMERS.ID, CUSTOMERS.LASTNAME, CUSTOMERS.FIRSTNAME, 
sum(PRODUCTS.PRICE)). 
from(CUSTOMERS). 
join(ORDERS).on(ORDERS.CUSTOMER_ID.eq(CUSTOMERS.ID)). 
join(ORDERITEMS).on(ORDERITEMS.ORDER_ID.eq(ORDERS.ID)). 
join(PRODUCTS).on(PRODUCTS.ID.eq(ORDERITEMS.PRODUCT_ID)). 
groupBy(CUSTOMERS.ID, CUSTOMERS.NAME). 
orderBy(CUSTOMERS.NAME). 
fetchInto(CustomersInfoDTO.class); 
jOOQ: http://www.jooq.org
CQRS 
Quelle: Martin Fowler, http://martinfowler.com/bliki/CQRS.html
CQRS IM KLEINEN 
• QUERIES 
– JPA Constructor Expression 
– JPA ConstructorResult 
– QLRM 
– jOOQ 
• COMMANDS 
– JPA Entities
EMPFEHLUNGEN 
• Entities zum Erstellen und Ändern der Daten 
• DTO für lesende Zugriffe 
– Constructor Expression 
– SQL mit QLRM oder jOOQ
BONUS MATERIAL
RANDOM-DATA-GENERATOR 
RandomDataGenerator randomDataGenerator = new RandomDataGenerator(); 
List<Customer> customers = randomDataGenerator.generateList( 
400, 
new GenConfig() 
.name(Name.Firstname, "firstname") 
.name(Name.Lastname, "lastname"), 
Customer.class);
LOG4JDBC 
Anpassungen im META-INF/persistence.xml 
<property name="javax.persistence.jdbc.url" 
value="jdbc:log4jdbc:derby://localhost:1527/orders"/> 
<property name="javax.persistence.jdbc.driver" 
value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"/> 
log4jdbc-log4j2: https://code.google.com/p/log4jdbc-log4j2/

Weitere ähnliche Inhalte

Was ist angesagt?

MySQL Optimizer: What’s New in 8.0
MySQL Optimizer: What’s New in 8.0MySQL Optimizer: What’s New in 8.0
MySQL Optimizer: What’s New in 8.0oysteing
 
C programs Set 4
C programs Set 4C programs Set 4
C programs Set 4Koshy Geoji
 
SPFx working with SharePoint data
SPFx working with SharePoint dataSPFx working with SharePoint data
SPFx working with SharePoint dataVladimir Medina
 
SPFx: Working with SharePoint Content
SPFx: Working with SharePoint ContentSPFx: Working with SharePoint Content
SPFx: Working with SharePoint ContentVladimir Medina
 
Import data from csv excel file and export to xml excel file in c programming
Import data from csv excel file and export to xml excel file in c programmingImport data from csv excel file and export to xml excel file in c programming
Import data from csv excel file and export to xml excel file in c programmingSalar Delavar Qashqai
 
Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片cfc
 
The Ring programming language version 1.5.2 book - Part 7 of 181
The Ring programming language version 1.5.2 book - Part 7 of 181The Ring programming language version 1.5.2 book - Part 7 of 181
The Ring programming language version 1.5.2 book - Part 7 of 181Mahmoud Samir Fayed
 
Histogram Support in MySQL 8.0
Histogram Support in MySQL 8.0Histogram Support in MySQL 8.0
Histogram Support in MySQL 8.0oysteing
 
Revision c odesagain
Revision c odesagainRevision c odesagain
Revision c odesagainrex0721
 
The Ring programming language version 1.6 book - Part 9 of 189
The Ring programming language version 1.6 book - Part 9 of 189The Ring programming language version 1.6 book - Part 9 of 189
The Ring programming language version 1.6 book - Part 9 of 189Mahmoud Samir Fayed
 
Sfdgr 12 20180906_answer_v1.0
Sfdgr 12 20180906_answer_v1.0 Sfdgr 12 20180906_answer_v1.0
Sfdgr 12 20180906_answer_v1.0 Ikou Sanuki
 
The Ring programming language version 1.7 book - Part 10 of 196
The Ring programming language version 1.7 book - Part 10 of 196The Ring programming language version 1.7 book - Part 10 of 196
The Ring programming language version 1.7 book - Part 10 of 196Mahmoud Samir Fayed
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneRafael Felix da Silva
 
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...Roel Hartman
 
Mcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singhMcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singhDIVYA SINGH
 
Storytelling By Numbers
Storytelling By NumbersStorytelling By Numbers
Storytelling By NumbersMichael King
 

Was ist angesagt? (20)

MySQL Optimizer: What’s New in 8.0
MySQL Optimizer: What’s New in 8.0MySQL Optimizer: What’s New in 8.0
MySQL Optimizer: What’s New in 8.0
 
Api presentation
Api presentationApi presentation
Api presentation
 
C programs Set 4
C programs Set 4C programs Set 4
C programs Set 4
 
SPFx working with SharePoint data
SPFx working with SharePoint dataSPFx working with SharePoint data
SPFx working with SharePoint data
 
SPFx: Working with SharePoint Content
SPFx: Working with SharePoint ContentSPFx: Working with SharePoint Content
SPFx: Working with SharePoint Content
 
Import data from csv excel file and export to xml excel file in c programming
Import data from csv excel file and export to xml excel file in c programmingImport data from csv excel file and export to xml excel file in c programming
Import data from csv excel file and export to xml excel file in c programming
 
Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片
 
Ruby - Design patterns tdc2011
Ruby - Design patterns tdc2011Ruby - Design patterns tdc2011
Ruby - Design patterns tdc2011
 
The Ring programming language version 1.5.2 book - Part 7 of 181
The Ring programming language version 1.5.2 book - Part 7 of 181The Ring programming language version 1.5.2 book - Part 7 of 181
The Ring programming language version 1.5.2 book - Part 7 of 181
 
Histogram Support in MySQL 8.0
Histogram Support in MySQL 8.0Histogram Support in MySQL 8.0
Histogram Support in MySQL 8.0
 
Revision c odesagain
Revision c odesagainRevision c odesagain
Revision c odesagain
 
The Ring programming language version 1.6 book - Part 9 of 189
The Ring programming language version 1.6 book - Part 9 of 189The Ring programming language version 1.6 book - Part 9 of 189
The Ring programming language version 1.6 book - Part 9 of 189
 
Sfdgr 12 20180906_answer_v1.0
Sfdgr 12 20180906_answer_v1.0 Sfdgr 12 20180906_answer_v1.0
Sfdgr 12 20180906_answer_v1.0
 
The Ring programming language version 1.7 book - Part 10 of 196
The Ring programming language version 1.7 book - Part 10 of 196The Ring programming language version 1.7 book - Part 10 of 196
The Ring programming language version 1.7 book - Part 10 of 196
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com Backbone
 
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
 
Mcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singhMcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singh
 
Stored procedures
Stored proceduresStored procedures
Stored procedures
 
MaintainStaffTable
MaintainStaffTableMaintainStaffTable
MaintainStaffTable
 
Storytelling By Numbers
Storytelling By NumbersStorytelling By Numbers
Storytelling By Numbers
 

Ähnlich wie Performante Java Enterprise Applikationen trotz O/R-Mapping

GraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learnedGraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learnedMarcinStachniuk
 
Spring Data for KSDG 2012/09
Spring Data for KSDG 2012/09Spring Data for KSDG 2012/09
Spring Data for KSDG 2012/09永昇 陳
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETTomas Jansson
 
Patterns of Enterprise Application Architecture (by example)
Patterns of Enterprise Application Architecture (by example)Patterns of Enterprise Application Architecture (by example)
Patterns of Enterprise Application Architecture (by example)Paulo Gandra de Sousa
 
PerlApp2Postgresql (2)
PerlApp2Postgresql (2)PerlApp2Postgresql (2)
PerlApp2Postgresql (2)Jerome Eteve
 
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project A
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project ADN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project A
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project ADataconomy Media
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateKiev ALT.NET
 
ADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael PizzoADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael PizzoHasnain Iqbal
 
Agile data presentation 3 - cambridge
Agile data   presentation 3 - cambridgeAgile data   presentation 3 - cambridge
Agile data presentation 3 - cambridgeRomans Malinovskis
 
MongoDB World 2018: Keynote
MongoDB World 2018: KeynoteMongoDB World 2018: Keynote
MongoDB World 2018: KeynoteMongoDB
 
The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31Mahmoud Samir Fayed
 
Open Source Search: An Analysis
Open Source Search: An AnalysisOpen Source Search: An Analysis
Open Source Search: An AnalysisJustin Finkelstein
 
Love Your Database Railsconf 2017
Love Your Database Railsconf 2017Love Your Database Railsconf 2017
Love Your Database Railsconf 2017gisborne
 
Advanced SQL For Data Scientists
Advanced SQL For Data ScientistsAdvanced SQL For Data Scientists
Advanced SQL For Data ScientistsDatabricks
 
PHP cart
PHP cartPHP cart
PHP carttumetr1
 
Advanced dot net
Advanced dot netAdvanced dot net
Advanced dot netssa2010
 

Ähnlich wie Performante Java Enterprise Applikationen trotz O/R-Mapping (20)

GraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learnedGraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learned
 
Spring Data for KSDG 2012/09
Spring Data for KSDG 2012/09Spring Data for KSDG 2012/09
Spring Data for KSDG 2012/09
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NET
 
PoEAA by Example
PoEAA by ExamplePoEAA by Example
PoEAA by Example
 
Patterns of Enterprise Application Architecture (by example)
Patterns of Enterprise Application Architecture (by example)Patterns of Enterprise Application Architecture (by example)
Patterns of Enterprise Application Architecture (by example)
 
PerlApp2Postgresql (2)
PerlApp2Postgresql (2)PerlApp2Postgresql (2)
PerlApp2Postgresql (2)
 
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project A
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project ADN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project A
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project A
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicate
 
My Sql concepts
My Sql conceptsMy Sql concepts
My Sql concepts
 
ADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael PizzoADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
 
Apache spark
Apache sparkApache spark
Apache spark
 
Agile data presentation 3 - cambridge
Agile data   presentation 3 - cambridgeAgile data   presentation 3 - cambridge
Agile data presentation 3 - cambridge
 
MongoDB World 2018: Keynote
MongoDB World 2018: KeynoteMongoDB World 2018: Keynote
MongoDB World 2018: Keynote
 
The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31
 
Open Source Search: An Analysis
Open Source Search: An AnalysisOpen Source Search: An Analysis
Open Source Search: An Analysis
 
Love Your Database Railsconf 2017
Love Your Database Railsconf 2017Love Your Database Railsconf 2017
Love Your Database Railsconf 2017
 
Advanced SQL For Data Scientists
Advanced SQL For Data ScientistsAdvanced SQL For Data Scientists
Advanced SQL For Data Scientists
 
PHP cart
PHP cartPHP cart
PHP cart
 
Dat402
Dat402Dat402
Dat402
 
Advanced dot net
Advanced dot netAdvanced dot net
Advanced dot net
 

Kürzlich hochgeladen

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 

Kürzlich hochgeladen (20)

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 

Performante Java Enterprise Applikationen trotz O/R-Mapping

  • 1. PERFORMANTE JAVA ENTERPRISE APPLIKATIONEN TROTZ O/R-MAPPING Simon Martinelli, simas GmbH @simas_ch | about.me/simas_ch https://github.com/simasch/orders
  • 4. N+1 SELECT PROBLEM • Orders und OrderItems = FetchType.LAZY @OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, orphanRemoval = true) private Set<Order> orders; @OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true) private List<OrderItem> items; • Ein Query für alle Customers • Pro Customer 1 Query für die Orders • Pro Order 1 Query für die OrderItems
  • 5. LÖSUNGSANSÄTZE • FetchType.EAGER oder EntityGraph (JPA 2.1) – Nur ein Hinweis für JPA – != SQL JOIN – Hibernate erlaubt nur eine List mit FetchType.EAGER pro Entity org.hibernate.HibernateException: cannot simultaneously fetch multiple bags • JOIN FETCH – Achtung vor kartesischen Produkten
  • 6. DTO Quelle: Martin Fowler, http://martinfowler.com/eaaCatalog/dataTransferObject.html
  • 7. CustomerInfoDTO public class CustomerInfoDTO { private final Long id; private final String lastname; private final String firstname; private final double revenue; public CustomerInfoDTO(Long id, String lastname, String firstname, double revenue) { this.id = id; this.lastname = lastname; this.firstname = firstname; this.revenue = revenue; } ...
  • 8. CONSTRUCTOR EXPRESSION Query q = em.createQuery( "SELECT " + "NEW control.CustomerInfoDTO(c.id, c.lastname, c.firstname," + "SUM(i.product.price)) " + "FROM Customer c " + "JOIN c.orders o " + "JOIN o.items i " + "GROUP BY c.lastnamem, c.firstname" + "ORDER BY c.lastname, c.firstname"); List<CustomerInfoDTO> list = q.getResultList();
  • 9. DAS DATENMODELL IM ZENTRUM • Ein 1-1 Abbild der Datenbank in Entities oft unnötig X
  • 10. WAS IST MIT JPQL OHNE DIE BEZIEHUNG CUSTOMER->ORDER? NEU IN JPA 2.1 Query q = em.createQuery( "SELECT " + "NEW control.CustomerInfoDTO(c.id, c.lastname, c.firstname, " + "SUM(i.product.price)) " + "FROM Customer c " + "JOIN c.orders o ON o.customerId = c.id " + "JOIN o.items i " + "GROUP BY c.lastname, c.firstname" + "ORDER BY c.lastname, c.firstname"); List<CustomerInfoDTO> list = q.getResultList();
  • 11. ORM FÜR ALLES? Just because you're using Hibernate, doesn't mean you have to use it for everything. A point I've been making for about ten years now. Gavin King, 10.12.2013
  • 12. SQL? • VORTEILE – Testbar mit SQL Developer/TOAD/IDE – Optimierbar (Execution Plan) • ABER SQL VON HAND? NEIN! – JPA 2.1 ConstructorResult – QLRM – jOOQ
  • 13. JPA 2.1 CONSTRUCTOR RESULT Query q = em.createNativeQuery( "SELECT C.ID, C.LASTNAME, C.FIRSTNAME, SUM(P.PRICE) AS REVENUE" + "FROM CUSTOMERS C " + "JOIN ORDERS O ON O.CUSTOMER_ID = C.ID " + "JOIN ORDERITEMS I ON I.ORDER_ID = O.ID " + "JOIN PRODUCTS P ON P.ID = I.PRODUCT_ID " + "GROUP BY C.ID, C.LASTNAME, C.FIRSTNAME " + "ORDER BY C.LASTNAME, C.FIRSTNAME", "CustomerInfoDTO"); @SqlResultSetMapping(name="CustomerInfoDTO", classes={ @ConstructorResult(targetClass=CustomerInfoDTO.class, columns={@ColumnResult(name="ID"), @ColumnResult(name="LASTNAME"), @ColumnResult(name="FIRSTNAME"), @ColumnResult(name="REVENUE", type=Double.class)}) })
  • 14. QLRM Query q = em.createNativeQuery( "SELECT C.ID, C.LASTNAME, C.FIRSTNAME, SUM(P.PRICE) AS REVENUE" + "FROM CUSTOMERS C " + "JOIN ORDERS O ON O.CUSTOMER_ID = C.ID " + "JOIN ORDERITEMS I ON I.ORDER_ID = O.ID " + "JOIN PRODUCTS P ON P.ID = I.PRODUCT_ID " + "GROUP BY C.ID, C.LASTNAME, C.FIRSTNAME " + "ORDER BY C.LASTNAME, C.FIRSTNAME"); JpaResultMapper mapper = new JpaResultMapper(); List<CustomerInfoDTO> list = jpaResultMapper.list(q, CustomerInfoDTO.class); QLRM: https://github.com/simasch/qlrm
  • 15. jOOQ List<CustomersInfoDTO> list = create. select(CUSTOMERS.ID, CUSTOMERS.LASTNAME, CUSTOMERS.FIRSTNAME, sum(PRODUCTS.PRICE)). from(CUSTOMERS). join(ORDERS).on(ORDERS.CUSTOMER_ID.eq(CUSTOMERS.ID)). join(ORDERITEMS).on(ORDERITEMS.ORDER_ID.eq(ORDERS.ID)). join(PRODUCTS).on(PRODUCTS.ID.eq(ORDERITEMS.PRODUCT_ID)). groupBy(CUSTOMERS.ID, CUSTOMERS.NAME). orderBy(CUSTOMERS.NAME). fetchInto(CustomersInfoDTO.class); jOOQ: http://www.jooq.org
  • 16. CQRS Quelle: Martin Fowler, http://martinfowler.com/bliki/CQRS.html
  • 17. CQRS IM KLEINEN • QUERIES – JPA Constructor Expression – JPA ConstructorResult – QLRM – jOOQ • COMMANDS – JPA Entities
  • 18. EMPFEHLUNGEN • Entities zum Erstellen und Ändern der Daten • DTO für lesende Zugriffe – Constructor Expression – SQL mit QLRM oder jOOQ
  • 20. RANDOM-DATA-GENERATOR RandomDataGenerator randomDataGenerator = new RandomDataGenerator(); List<Customer> customers = randomDataGenerator.generateList( 400, new GenConfig() .name(Name.Firstname, "firstname") .name(Name.Lastname, "lastname"), Customer.class);
  • 21. LOG4JDBC Anpassungen im META-INF/persistence.xml <property name="javax.persistence.jdbc.url" value="jdbc:log4jdbc:derby://localhost:1527/orders"/> <property name="javax.persistence.jdbc.driver" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"/> log4jdbc-log4j2: https://code.google.com/p/log4jdbc-log4j2/