SlideShare une entreprise Scribd logo
1  sur  94
Advanced Hibernate Presented by   Haitham Raik
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Agenda
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Agenda  (cont.)
THE PERSISTENCE LIFECYCLE
The persistence lifecycle get() load() find() list() scroll() Iterate() uniqueResult() Transient Persistent Detached Removed save() saveOrUpdate() merge() persist() evict() close() clear() update() saveOrUpdate() lock() merge() delete()
THE PERSISTENCE CONTEXT
[object Object],[object Object],[object Object],[object Object],[object Object],The persistence context
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],The persistence context  (cont.)
[object Object],[object Object],[object Object],[object Object],The persistence context  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],The persistence context  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],The persistence context  (cont.)
OBJECT EQUALITY
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Object equality
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Object equality  (cont.)
FLUSH MODES
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Flush mode
THE PERSISTENCE MANAGER
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],The persistence manager
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],The persistence manager  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],The persistence manager  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],The persistence manager  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],The persistence manager  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],The persistence manager  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],The persistence manager  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],The persistence manager  (cont.)
TRANSACTIONS
[object Object],[object Object],[object Object],[object Object],Transactions
[object Object],[object Object],[object Object],Transactions  (cont.)
[object Object],[object Object],[object Object],Transactions  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Transactions  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],Transactions  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Transactions  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Transactions  (cont.)
CONTEXTUAL SESSION
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Contextual session
CONCURRENCY
[object Object],[object Object],Concurrency
[object Object],Concurrency  (cont.)
[object Object],Concurrency  (cont.)
[object Object],Concurrency  (cont.) Tx B Tx A 4. Commit 6. Commit
[object Object],Concurrency  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],Concurrency  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Concurrency  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],Concurrency  (cont.) Tx B Tx A 4. Commit 6. Commit
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Concurrency  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Concurrency  (cont.)
CACHING
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Caching
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Caching  (cont.)
[object Object],[object Object],[object Object],Caching  (cont.)
[object Object],[object Object],[object Object],[object Object],Caching  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],Caching  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Caching  (cont.)
BULK AND BATCH OPERATIONS
[object Object],[object Object],[object Object],[object Object],Bulk and batch operations
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Bulk and batch operations  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Bulk and batch operations  (cont.)
[object Object],[object Object],[object Object],Bulk and batch operations
FILTERS
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Filters
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Filters  (cont.)
INTERCEPTORS
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Interceptors
[object Object],[object Object],[object Object],[object Object],[object Object],Interceptors  (cont.)
THE CORE EVENT SYSTEM
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],The core event system
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],The core event system  (cont.)
FETCHING PLANS
[object Object],[object Object],[object Object],Fetching plans
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Fetching plans  (cont.) In the figure associated proxies are just forign keys in the item’s row
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Fetching plans  (cont.) User Company Address
FETCHING STRATEGIES
[object Object],[object Object],[object Object],[object Object],[object Object],Fetching strategies
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Fetching strategies  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Fetching strategies  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Fetching strategies  (cont.)
ADVANCED QUERY OPTIONS
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Advanced query
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Advanced query  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Advanced query  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],Advanced query  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Advanced query  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Advanced query  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Advanced query  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Advanced query  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],Advanced query  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Advanced query  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],Advanced query  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Advanced query – HQL  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Advanced query – Criteria  (cont.)
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Advanced query – Criteria  (cont.)
TOOLSET
ToolSet
Advanced Hibernate Thank you

Contenu connexe

Tendances

Sustaining Test-Driven Development
Sustaining Test-Driven DevelopmentSustaining Test-Driven Development
Sustaining Test-Driven Development
AgileOnTheBeach
 
Servletand sessiontracking
Servletand sessiontrackingServletand sessiontracking
Servletand sessiontracking
vamsi krishna
 
From Runnable and synchronized To atomically() and parallel()
From Runnable and synchronized To atomically() and parallel()From Runnable and synchronized To atomically() and parallel()
From Runnable and synchronized To atomically() and parallel()
José Paumard
 
The art of reverse engineering flash exploits
The art of reverse engineering flash exploitsThe art of reverse engineering flash exploits
The art of reverse engineering flash exploits
Priyanka Aash
 

Tendances (20)

Sustaining Test-Driven Development
Sustaining Test-Driven DevelopmentSustaining Test-Driven Development
Sustaining Test-Driven Development
 
JPA Best Practices
JPA Best PracticesJPA Best Practices
JPA Best Practices
 
Data in Motion: Streaming Static Data Efficiently
Data in Motion: Streaming Static Data EfficientlyData in Motion: Streaming Static Data Efficiently
Data in Motion: Streaming Static Data Efficiently
 
Servletand sessiontracking
Servletand sessiontrackingServletand sessiontracking
Servletand sessiontracking
 
Don't Make Android Bad... Again
Don't Make Android Bad... AgainDon't Make Android Bad... Again
Don't Make Android Bad... Again
 
Modern Android app library stack
Modern Android app library stackModern Android app library stack
Modern Android app library stack
 
Jasig Cas High Availability - Yale University
Jasig Cas High Availability -  Yale UniversityJasig Cas High Availability -  Yale University
Jasig Cas High Availability - Yale University
 
From Runnable and synchronized To atomically() and parallel()
From Runnable and synchronized To atomically() and parallel()From Runnable and synchronized To atomically() and parallel()
From Runnable and synchronized To atomically() and parallel()
 
Design Patterns Reconsidered
Design Patterns ReconsideredDesign Patterns Reconsidered
Design Patterns Reconsidered
 
The art of reverse engineering flash exploits
The art of reverse engineering flash exploitsThe art of reverse engineering flash exploits
The art of reverse engineering flash exploits
 
Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor Concurrency
 
Qt Framework Events Signals Threads
Qt Framework Events Signals ThreadsQt Framework Events Signals Threads
Qt Framework Events Signals Threads
 
Let's Build A Blockchain... in 40 minutes!
Let's Build A Blockchain... in 40 minutes!Let's Build A Blockchain... in 40 minutes!
Let's Build A Blockchain... in 40 minutes!
 
Слава Бобик «NancyFx для самых маленьких»
Слава Бобик «NancyFx для самых маленьких»Слава Бобик «NancyFx для самых маленьких»
Слава Бобик «NancyFx для самых маленьких»
 
The Ring programming language version 1.8 book - Part 105 of 202
The Ring programming language version 1.8 book - Part 105 of 202The Ring programming language version 1.8 book - Part 105 of 202
The Ring programming language version 1.8 book - Part 105 of 202
 
Java
JavaJava
Java
 
04 threads
04 threads04 threads
04 threads
 
Thread syncronization
Thread syncronizationThread syncronization
Thread syncronization
 
The zen of async: Best practices for best performance
The zen of async: Best practices for best performanceThe zen of async: Best practices for best performance
The zen of async: Best practices for best performance
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
 

En vedette

Presentacion Slideshare Xime
Presentacion Slideshare XimePresentacion Slideshare Xime
Presentacion Slideshare Xime
xime_divastar
 

En vedette (14)

CURRICULUM VITAE
CURRICULUM VITAECURRICULUM VITAE
CURRICULUM VITAE
 
Kampanje din optiker sommer 2016
Kampanje din optiker sommer 2016Kampanje din optiker sommer 2016
Kampanje din optiker sommer 2016
 
Las tic
Las ticLas tic
Las tic
 
Aciones para favoreser la salud qywuuey
Aciones para favoreser la salud qywuueyAciones para favoreser la salud qywuuey
Aciones para favoreser la salud qywuuey
 
JA Family Education Day Keynote: The Ups and Downs of Arthritis--How to foste...
JA Family Education Day Keynote: The Ups and Downs of Arthritis--How to foste...JA Family Education Day Keynote: The Ups and Downs of Arthritis--How to foste...
JA Family Education Day Keynote: The Ups and Downs of Arthritis--How to foste...
 
Psychology CV Newest
Psychology CV NewestPsychology CV Newest
Psychology CV Newest
 
Affecto (kort vers)
Affecto (kort vers)Affecto (kort vers)
Affecto (kort vers)
 
Presentacion Slideshare Xime
Presentacion Slideshare XimePresentacion Slideshare Xime
Presentacion Slideshare Xime
 
La gatita miedosa
La gatita miedosaLa gatita miedosa
La gatita miedosa
 
Acciones para favorecer la salud 1
Acciones para favorecer   la salud 1Acciones para favorecer   la salud 1
Acciones para favorecer la salud 1
 
Brand Avatars
Brand AvatarsBrand Avatars
Brand Avatars
 
Евгений Капинос "Advanced JPA (Java Persistent API)"
Евгений Капинос "Advanced JPA (Java Persistent API)"Евгений Капинос "Advanced JPA (Java Persistent API)"
Евгений Капинос "Advanced JPA (Java Persistent API)"
 
Lead & Arsenic poisoning in America
 Lead & Arsenic poisoning in America Lead & Arsenic poisoning in America
Lead & Arsenic poisoning in America
 
Arduino compatible layer (with 6LoWPAN) on Contiki
Arduino compatible layer (with 6LoWPAN) on ContikiArduino compatible layer (with 6LoWPAN) on Contiki
Arduino compatible layer (with 6LoWPAN) on Contiki
 

Similaire à Advanced Hibernate

09 Application Design
09 Application Design09 Application Design
09 Application Design
Ranjan Kumar
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Mario Fusco
 

Similaire à Advanced Hibernate (20)

09 Application Design
09 Application Design09 Application Design
09 Application Design
 
Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)
 
Think Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSThink Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJS
 
Implementing STM in Java
Implementing STM in JavaImplementing STM in Java
Implementing STM in Java
 
Jpa buenas practicas
Jpa buenas practicasJpa buenas practicas
Jpa buenas practicas
 
C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
 
Async Best Practices
Async Best PracticesAsync Best Practices
Async Best Practices
 
Rx workshop
Rx workshopRx workshop
Rx workshop
 
Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30) Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30)
 
Google App Engine Developer - Day3
Google App Engine Developer - Day3Google App Engine Developer - Day3
Google App Engine Developer - Day3
 
Pharos
PharosPharos
Pharos
 
Async Debugging A Practical Guide to survive !
Async Debugging A Practical Guide to survive !Async Debugging A Practical Guide to survive !
Async Debugging A Practical Guide to survive !
 
Hibernate An Introduction
Hibernate An IntroductionHibernate An Introduction
Hibernate An Introduction
 
Deuce STM - CMP'09
Deuce STM - CMP'09Deuce STM - CMP'09
Deuce STM - CMP'09
 
Online Meetup: Why should container system / platform builders care about con...
Online Meetup: Why should container system / platform builders care about con...Online Meetup: Why should container system / platform builders care about con...
Online Meetup: Why should container system / platform builders care about con...
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2
 
Using Apache Spark to Solve Sessionization Problem in Batch and Streaming
Using Apache Spark to Solve Sessionization Problem in Batch and StreamingUsing Apache Spark to Solve Sessionization Problem in Batch and Streaming
Using Apache Spark to Solve Sessionization Problem in Batch and Streaming
 
Concurrency gotchas
Concurrency gotchasConcurrency gotchas
Concurrency gotchas
 

Plus de Haitham Raik (11)

History of Software Architecture
History of Software ArchitectureHistory of Software Architecture
History of Software Architecture
 
Unified Microservices Patterns List
Unified Microservices Patterns ListUnified Microservices Patterns List
Unified Microservices Patterns List
 
GIT In Detail
GIT In DetailGIT In Detail
GIT In Detail
 
PCI security requirements secure coding and code review 2014
PCI security requirements   secure coding and code review 2014PCI security requirements   secure coding and code review 2014
PCI security requirements secure coding and code review 2014
 
PCI Security Requirements - secure coding
PCI Security Requirements - secure codingPCI Security Requirements - secure coding
PCI Security Requirements - secure coding
 
Red hat linux essentials
Red hat linux essentialsRed hat linux essentials
Red hat linux essentials
 
Object Oriented Analysis and Design with UML2 part2
Object Oriented Analysis and Design with UML2 part2Object Oriented Analysis and Design with UML2 part2
Object Oriented Analysis and Design with UML2 part2
 
Object Oriented Analysis and Design with UML2 part1
Object Oriented Analysis and Design with UML2 part1Object Oriented Analysis and Design with UML2 part1
Object Oriented Analysis and Design with UML2 part1
 
IBM OOAD Part1 Summary
IBM OOAD Part1 SummaryIBM OOAD Part1 Summary
IBM OOAD Part1 Summary
 
JEE5 New Features
JEE5 New FeaturesJEE5 New Features
JEE5 New Features
 
JMX
JMXJMX
JMX
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Dernier (20)

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Advanced Hibernate

Notes de l'éditeur

  1. persistence lifecycle: the states an object goes through during its life However, one of the key factors of your success with Hibernate is your understanding of state management Transient: transient, which means they aren’t associated with any database table row and so their state is lost as soon as they’re no longer referenced by any other object. any modification of a transient instance isn’t known to a persistence context (they are not transactional) Objects that are referenced only by other transient instances are transient. Persistent: An entity instance with a database identity Persistent instances are always associated with a persistence context Detached: detached, indicating that their state is no longer guaranteed to be synchronized with database state (they’re no longer attached to a persistence context) Hibernate offers two operations, reattachment and merging, to reattach .
  2. One session has one internal persistence context (it isn’t something you see in your application) It is useful because we can extend it for a long conversation.
  3. Automatic dirty check: Hibernate propagates state changes to the database as late as possible but hides this detail from the application (to keep lock times in the Database as short as possible) Hibernate is able to detect exactly which properties have been modified. it’s possible to include only the columns that need updating in the SQL UPDATE (This may bring some performance gains. However, it’s usually not a significant difference and, in theory, could harm performance in some environments). The setting in the class mapping file. We recommend you consider this setting when you have an extraordinarily large number of columns in a table (say, more than 50);
  4. Using Database identifier we can know whether two objects match the same record in the database or no. In the most cases the Database identifier is the record primary key The question is it possible to have two different objects match the same record? Or is it always two objects will match two different object. For the scope of object identity we have three common choices: no identity scope: we got the record twice in the same trxn then we will get two different objects if we made two different changes on the two objects. How should we decide which state should be propagated to the Database? session-scoped identity : process scoped identity: one object in the whole JVM. The problem is that we need to synchronize the objects in the multithreaded systems which is expensive.
  5. Do not treat detached objects as identical in memory
  6. Set does not allow duplicate entries, to determine whether the object is exist or no it uses the equals() The default impl of equals uses the == The Answer: If the equals() method implemented the size is one, otherwise it is two. This can lead to problems if you treat them as equal in detached state.
  7. Database identifier can’t be used for transient objects All properties: may cause un equal objects in case two objects from two sessions where one object has been changed
  8. Database identifier for associated object: For example, a candidate business key for the Bid class is the identifier of the Item it was made for together with the bid amount. Another example user name and company id as business key for the user
  9. Write-behinds usefulness: coalesce many changes into a minimal number of database requests Shorter lock durations inside the database. Take advantage of the JDBC Batch.
  10. Persistence manager exposed in many interfaces: Session, Query, Criteria and Transaction Manager services CRUD, Query execution, Trxn mgmt, management of persistence context. SAVE operation: Call to save() does not mean (all the time) an immediate SQL insert stmt execution. That’s depend on the id generator. It’s better to fully initialize the object before managing it with a session.
  11. get(): return null if object not exist. Always return object load(): throws ObjectNotFoundException Return proxy (placeholder, wrapper for the id)
  12. Here we use the automatic dirty check service to get whether the object changed or no
  13. The item object is in removed state after you call delete(); you shouldn’t continue working with it, and, in most cases, you should make sure any reference to it in your application is removed. Do I have to load an object to delete it? Yes, an object has to be loaded into the persistence context; an instance has to be in persistent state to be removed (note that a proxy is good enough). The reason is the interceptors. Otherwise use Bulk operations. hibernate.use_identifier_rollback configuration option: Hibernate sets the database identifier property of the deleted item to null after deletion and flushing. It’s then a clean transient instance.
  14. Replication: retrieve objects from one database and store them in another. ■ ReplicationMode.IGNORE —Ignores the object when there is an existing database row with the same identifier in the target database. ■ ReplicationMode.OVERWRITE —Overwrites any existing database row with the same identifier in the target database. ■ ReplicationMode.EXCEPTION —Throws an exception if there is an existing database row with the same identifier in the target database. ■ ReplicationMode.LATEST_VERSION —Overwrites the row in the target database if its version is earlier than the version of the object, or ignores the object otherwise. Requires enabled Hibernate optimistic concurrency control.
  15. It doesn’t matter if the item object is modified before or after it’s passed to update() . The important thing here is that the call to update() is reattaching the detached instance to the new Session (and persistence context). Hibernate always treats the object as dirty and schedules an SQL UPDATE ., which will be executed during flush. select-before-update=“true” (mapping config) : Hibernate determines whether the object is dirty by executing a SELECT statement and comparing the object’s current state to the current database state
  16. Changes made before the call to lock() aren’t propagated to the database
  17. Database transactions have to be short (to keep resources available). In practice, you also need a concept, that allows you to have long-running conversations. Conversations allow the user of your application to have think-time, while still guaranteeing atomic, isolated, and consistent behavior.
  18. Hibernate doesn’t roll back in-memory changes to persistent objects
  19. The main benefit, however, is tight integration with persistence context management —for example, a Session is flushed automatically when you commit
  20. Is it faster to roll back read-only transactions? some developers found this to be faster in some special circumstances The book authors tested this with the more popular database systems and found no difference. And there is no reason why a database system should have a suboptimal implementation No source of real numbers showing a performance difference Always commit your transaction and roll back if the commit fails.
  21. manager_lookup_class example: org.hibernate.transaction.JBossTransactionManagerLookup org.hibernate.transaction.WebSphereTransactionManagerLookup
  22. It is recommended to use JTA interface directly.
  23. If you configure Hibernate to use CMT, it knows that it should flush and close a Session that participates in a system transaction automatically.
  24. Using the jta session context if no current session associated with the current JTA transaction one will be started and associated with that transaction. Note that for backwards compatibility, if hibernate.current_session_context_class is not set but a org.hibernate.transaction.TransactionManagerLookup is configured, Hibernate will use the org.hibernate.context.JTASessionContext The Sessions retrieved via getCurrentSession() in "jta" context will be set to automatically flush before the transaction completes, close after the transaction completes, and aggressively release JDBC connections after each statement.
  25. These options work in case using JDBC transaction but will not work in case datasource
  26. From time to time, it’s useful to specify a more restrictive lock for a particular transaction switching all database connections to a higher isolation level than read committed, but this is a bad default when scalability of the application is a concern. You need better isolation guarantees only for a particular unit of work
  27. From time to time, it’s useful to specify a more restrictive lock for a particular transaction switching all database connections to a higher isolation level than read committed, but this is a bad default when scalability of the application is a concern. You need better isolation guarantees only for a particular unit of work
  28. Trans action scope cache— Attached to the current unit of work, which may be a database transaction or even a conversation. It’s valid and used only as long as the unit of work runs. Every unit of work has its own cache. Data in this cache isn’t accessed concurrently. ■ Process scope cache— Shared between many (possibly concurrent) units of work or transactions. This means that data in the process scope cache is accessed by concurrently running threads, obviously with implications on transaction isolation. ■ Cluster scope cache— Shared between multiple processes on the same machine or between multiple machines in a cluster. Here, network communication is an important point worth consideration.
  29. it’s neither necessary nor desirable to have identical objects in two concurrent threads. Locks held in memory should be avoided for web and enterprise applications. In cluster the communication is required for consistency Process-scoped cache (Return by value used by hibernate as second level cache) Cluster-scoped cache (it might be the second level cache)
  30. Transactional—Available in a managed environment only, it guarantees full transactional isolation up to repeatable read, if required. Use this strategy for read-mostly data where it’s critical to prevent stale data in concurrent transactions, in the rare case of an update. Read-write—This strategy maintains read committed isolation, using a timestamping mechanism and is available only in nonclustered environments. Again, use this strategy for read-mostly data where it’s critical to prevent stale data in concurrent transactions, in the rare case if an update. Nonstrict-read-write—Makes no guarantee of consistency between the cache and the database. If there is a possibility of concurrent access to the same entity, you should configure a sufficiently short expiry timeout. Otherwise, you may read stale data from the cache. Use this strategy if data hardly ever changes (many hours, days, or even a week) and a small likelihood of stale data isn’t of critical concern. ■ Read-only—A concurrency strategy suitable for data which never changes. Use it for reference data only.
  31. Session.evict(object) to remove an element from the first level cache Session.clear() to remove all items in the first level cache SessionFactory.evict(class) remove from the second level cache all the instances with the same type SessionFactory.evict(class, id) remove the element from the second level cache
  32. VIPCustomer must be subclass of Customer.
  33. But instead of retrieving the result of the query completely into memory, you open an online cursor. A cursor is a pointer to a result set that stays in the database. To avoid memory exhaustion, you flush() and clear() the persistence context before loading the next 100 objects into it.
  34. Note that you should disable the second-level cache for any batch operations; otherwise, each modification of an object during the batch procedure must be propagated to the second-level cache for that persistent class. This is an unnecessary overhead.
  35. Filter is an alternative to dynamic database view with dynamic parameterization at runtime. For example, the currently logged-in application user may not have the rights to see everything.
  36. Filter is an alternative to dynamic database view with dynamic parameterization at runtime. For example, the currently logged-in application user may not have the rights to see everything.
  37. Useful for the audit log of all object modifications Do not use the session in the interceptor rather than use temporary session Interceptor has many other methods. You can use marker interface to mark all classes that should be intercepted. postFlush() is the correct place for logging (auditing) to guarantee the id existence.
  38. You can create a stack of listeners
  39. The figure: the load does not execute any SQL statement till it is necessary this is opposite to the get() method which always hits the DB. Load returns a proxy Proxies are placeholders that are generated at runtime Proxy is a sub class of the actual bean, so it is required to make all hibernate beans with no private const and no param cons
  40. Some times you need to an entity should always be loaded into memory and no place holder should be returned instead. Disabling proxy generation for a particular entity : load() method will try to load the userBean without initialization but when it tries to create company proxy it can’t because it is disabled so it will make an immediate SELECT stmt to fetch both the userBean and companyBean. Some times you want to specify that a particular association should always be loaded
  41. The goal of Fetching strategy is to minimize the number of SQL statements and to simplify the SQL statements, so that querying can be as sufficient as possible.
  42. In this example: telling Hibernate to pre-fetch up to 10 uninitialized proxies Instead of n+1 selects, you now see n/10+1 selects to retrieve the required collections into memory
  43. Obviously, the seller is no longer lazily loaded on demand, but immediately with join. with lazy="false", you see an immediate second SELECT With fetch="join", you get the seller loaded in the same single SELECT Max fetch depth: Recommended values from 1-5 tables Max fetch depth: 0 will disable join fetching Do not use global fetch join rather than use dynamic fetching
  44. FlushMode.COMMIT: does not flush before the query execution (when you don’t need to flush your modifications to the database before executing a query, because conflicting results aren’t a problem) CacheMode.IGNORE: any object retrieved by this query isn’t put in the second-level cache. setReadOnly(): disable the auto-dirty check setTimeout(): long a query is allowed to run by setting a timeout setFetchSize(): can improve data retrieval if you execute a query with list() setLockMode(): pessimistic lock (a lock is held until the end of the database transaction) setComment(): hibernate add your custom comment to each sql stmt it writes to the logs
  45. List: One or several SELECT statements are executing immediately, depending on your fetch plan. Iterate Hibernate retrieves only the primary key (identifier) values of entity objects in a first SQL SELECT, and then tries to find the rest of the state of the objects in the persistence context cache, and (if enabled) the second-level cache. Otherwise it will fetch the record using an additional SELECT for each turn. It is effective only if the second level cache enabled for the iterated entity. Otherwise it will execute n+1 problem. Scroll Uses a cursor that is held on the database The cursor points to a particular row in the result of a query, and the application can move the cursor forward and backword. Use it when you need to execute statements that may return too large results that you want to keep at the database level. For example you need all the data but want to retrieve it in several steps. Stop the curose before database transaction.
  46. Any function that is called in the WHERE clause of an HQL statement, and that isn’t known to Hibernate, is passed directly to the database, as an SQL function call. You have to register a function in your org.hibernate.Dialect to enable it for the SELECT clause in HQL.
  47. These are scalar values, not entity instances. Therefore, they aren’t in any persistent state, like an entity instance would be. They aren’t transactional and obviously aren’t checked automatically for dirty state. The Object[]s returned by this query contain a Long at index 0, a String at index 1, and int at index 2 Demo how to use aggregate functions in the where and select. Demo how to use SQL functions in the where and select. The StudentSummary class is a Java bean, it doesn’t have to be a mapped persistent entity class. On the other hand, if you use the SELECT NEW technique with a mapped entity class, all instances returned by your query are in transient .
  48. One property List of properties Aggregation functions Dynamic instantiation
  49. Implicit join can be used in many-to-one or one-to-one Demo how to use querying components with where How to use in select
  50. you have to assign an alias to a joined association Can be used for restrictions (inner join) Query1: This query returns list of Object[] object[0] is user and object[1] is company Query2: return only list of users rather than pair of users and its company as pair (if you try to access the company from user “user.getCompany()” the company will be loaded lazily). Addresses are not initialized tell they used. And user will be duplicated for each of his addresses Using DISTINCT No duplicates will be returned
  51. Inner join createCriteria for *-to-one fetch associated entity eagerly while in associated collections it will be lazy loaded
  52. List of users each user has an initialized company Distinct to prevent the duplicate data Uses the outer join Do not use iterate() Do not use setMaxResults In both queries will return list of users and its company in the same query (even if lazy enabled the both entities will be loaded immediately). Don’t fetch more than one collection in parallel (Cartesian product). You can fetch as many single-valued associated objects as you like. Dynamic fetching ignore any fetching strategy you have defined in mapping metadata. Reference duplicate may return, so you can use DISTINCT or Set to remove duplicates.
  53. createCriteria for *-to-one fetch associated entity eagerly while in associated collections it will be lazy loaded In case *-to-one by default it will be inner join createCriteria() in case *-to-one fetch eagerly and using inner join In case *-to-one setFetchMode Can be used as createCriteria but you can not add any restrictions on the associated entity In case associated collections I have to use the setFetchMode() to initialize the collection, but it will use the left outer join I have to use the CriteriaSpecification.INNER_JOIN if I want to use the eager fetching with inner join (note there is duplicates) Remove any duplicates
  54. The query result consists of ordered pairs
  55. Hibernate lets you externalize query strings to the mapping file.
  56. FlushMode.COMMIT: does not flush before the query execution (when you don’t need to flush your modifications to the database before executing a query, because conflicting results aren’t a problem) CacheMode.IGNORE: any object retrieved by this query isn’t put in the second-level cache. setReadOnly(): disable the auto-dirty check setTimeout(): long a query is allowed to run by setting a timeout setFetchSize(): can improve data retrieval if you execute a query with list() setLockMode(): pessimistic lock (a lock is held until the end of the database transaction) setComment(): hibernate add your custom comment to each sql stmt it writes to the logs