SlideShare a Scribd company logo
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/

More Related Content

What's hot

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
oysteing
 
Api presentation
Api presentationApi presentation
Api presentation
Susant Sahani
 
C programs Set 4
C programs Set 4C programs Set 4
C programs Set 4
Koshy Geoji
 
SPFx working with SharePoint data
SPFx working with SharePoint dataSPFx working with SharePoint data
SPFx working with SharePoint data
Vladimir Medina
 
SPFx: Working with SharePoint Content
SPFx: Working with SharePoint ContentSPFx: Working with SharePoint Content
SPFx: Working with SharePoint Content
Vladimir 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 programming
Salar Delavar Qashqai
 
Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片
cfc
 
Ruby - Design patterns tdc2011
Ruby - Design patterns tdc2011Ruby - Design patterns tdc2011
Ruby - Design patterns tdc2011
Rafael Felix da Silva
 
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
Mahmoud Samir Fayed
 
Histogram Support in MySQL 8.0
Histogram Support in MySQL 8.0Histogram Support in MySQL 8.0
Histogram Support in MySQL 8.0
oysteing
 
Revision c odesagain
Revision c odesagainRevision c odesagain
Revision c odesagain
rex0721
 
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
Mahmoud 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 196
Mahmoud Samir Fayed
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com Backbone
Rafael 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 singh
DIVYA SINGH
 
Stored procedures
Stored proceduresStored procedures
MaintainStaffTable
MaintainStaffTableMaintainStaffTable
MaintainStaffTable
William Rutherford
 
Storytelling By Numbers
Storytelling By NumbersStorytelling By Numbers
Storytelling By Numbers
Michael King
 

What's hot (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
 

Similar to 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 learned
MarcinStachniuk
 
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
Tomas Jansson
 
PoEAA by Example
PoEAA by ExamplePoEAA by Example
PoEAA by Example
Paulo Gandra de Sousa
 
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 A
Dataconomy Media
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicate
Kiev ALT.NET
 
My Sql concepts
My Sql conceptsMy Sql concepts
My Sql concepts
Pragya Rastogi
 
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
Hasnain Iqbal
 
Apache spark
Apache sparkApache spark
Apache spark
Arnon Rotem-Gal-Oz
 
Agile data presentation 3 - cambridge
Agile data   presentation 3 - cambridgeAgile data   presentation 3 - cambridge
Agile data presentation 3 - cambridge
Romans Malinovskis
 
MongoDB World 2018: Keynote
MongoDB World 2018: KeynoteMongoDB World 2018: Keynote
MongoDB World 2018: Keynote
MongoDB
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
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
Mahmoud Samir Fayed
 
Open Source Search: An Analysis
Open Source Search: An AnalysisOpen Source Search: An Analysis
Open Source Search: An Analysis
Justin Finkelstein
 
Love Your Database Railsconf 2017
Love Your Database Railsconf 2017Love Your Database Railsconf 2017
Love Your Database Railsconf 2017
gisborne
 
Advanced SQL For Data Scientists
Advanced SQL For Data ScientistsAdvanced SQL For Data Scientists
Advanced SQL For Data Scientists
Databricks
 
PHP cart
PHP cartPHP cart
PHP cart
tumetr1
 
Dat402
Dat402Dat402
Dat402
ssa2010
 

Similar to 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
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
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
 

Recently uploaded

E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 

Recently uploaded (20)

E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 

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/