SlideShare une entreprise Scribd logo
1  sur  27
Data Access with Hibernate Persistent objects and persistence contexts
Object state transitions and Session methods Transient Persistent Detached new garbage garbage delete() save() saveOrUpdate() get() load() find() iterate() etc. evict() close()* clear()* update() saveOrUpdate() lock() * affects all instances in a Session
Transient objects ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Persistent objects ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Detached objects ,[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 scope of object identity ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Hibernate identity scope Session session1 = sf.openSession(); Transaction tx1 = session.beginTransaction(); Object a = session1.load(Category.class, new Long(1234) ); Object b = session1.load(Category.class, new Long(1234) ); if ( a == b ) System.out.println("a and b are identicial and the same database identity."); tx1.commit(); session1.close(); Session session2 = sf.openSession(); Transaction tx2 = session.beginTransaction(); Object b2 = session2.load(Category.class, new Long(1234) ); if ( a != b2 ) System.out.println("a and b2 are not identical."); tx2.commit(); session2.close();
Outside of the identity scope ,[object Object],[object Object],[object Object]
Identity and equality contracts ,[object Object],[object Object],[object Object],[object Object],Session session1 = sf.openSession(); Transaction tx1 = session.beginTransaction(); Object  itemA  = session1.load(Item.class, new Long( 1234 ) ); tx1.commit(); session1.close(); Session session2 = sf.openSession(); Transaction tx2 = session.beginTransaction(); Object  itemB  = session2.load(Item.class, new Long( 1234 ) ); tx2.commit(); session2.close(); Set allObjects = new HashSet(); allObjects.add(itemA); allObjects.add(itemB); System.out.println(allObjects.size()); // How many elements?
Implementing  equals()  and  hashCode() ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],We need a  business key .
Using business keys for equality ,[object Object],[object Object],[object Object],public class Item { public boolean equals(Object other) { if (this == other) return true; if (!(other instanceof Item)) return false; final Item item = (Item) other; if (! getSummary() .equals(item.getSummary())) return false; if (! getCreated() .equals(item.getCreated())) return false; return true; } public int hashCode() { int result; result =  getSummary() .hashCode(); return 29 * result +  getCreated() .hashCode(); } }
The Hibernate Session ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Making an object persistent ,[object Object],[object Object],[object Object],User user = new User(); user.getName().setFirstName("John"); user.getName().setLastName("Doe"); Session session = sessions.openSession(); Transaction tx = session.beginTransaction(); session.save(user); tx.commit(); session.close();
Updating a detached instance ,[object Object],[object Object],[object Object],user.setPassword("secret"); Session sessionTwo = sessions.openSession(); Transaction tx = sessionTwo.beginTransaction(); sessionTwo.update(user); user.setLoginName("jonny"); tx.commit(); sessionTwo.close();
Locking a detached instance ,[object Object],[object Object],Session sessionTwo = sessions.openSession(); Transaction tx = sessionTwo.beginTransaction(); sessionTwo.lock(user, LockMode.NONE); user.setPassword("secret"); user.setLoginName("jonny"); tx.commit(); sessionTwo.close();
Retrieving objects ,[object Object],Session session = sessions.openSession(); Transaction tx = session.beginTransaction(); int userID = 1234; User user =  session.get (User.class, new Long(userID)); // "user" might be null if it doesn't exist tx.commit(); session.close();
Making a persistent object transient ,[object Object],[object Object],[object Object],Session session = sessions.openSession(); Transaction tx = session.beginTransaction(); int userID = 1234; User user = session.get(User.class, new Long(userID)); session.delete(user); tx.commit(); session.close();
Making a detached object transient ,[object Object],[object Object],Session session = sessions.openSession(); Transaction tx = session.beginTransaction(); session.delete(user); tx.commit(); session.close();
Persistence by reachability ,[object Object],Transient Persistent Persistent by Reachability Electronics: Category Cell Phones: Category Computer: Category Desktop PCs: Category Monitors: Category
Association cascade styles ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Association cascade styles ,[object Object],[object Object],[object Object],<class name=“Category” … > … <many-to-one name=“parentCategory”  column=“PARENT_ID” cascade=“none” /> <set name=“childCategories” cascade=“save-update” … > <key column=“PARENT_ID”/> <one-to-many class=“Category”/> </set> </class>
Adding a new category to object graph Computer: Category Laptops : Category Electronics: Category Cell Phones: Category Desktop PCs: Category Monitors: Category
Association cascade styles ,[object Object],[object Object],[object Object],Session session = sessions.openSession(); Transaction tx = session.begnTransaction(); Category computer = (Category)session.get(Category.class,computerID); Category laptops = new Category(“Laptops”); Compter.getChildCategories().add(laptops); Laptops.setParentCategory(computer); tx.commit(); session.close(); The computer instance is persisted(attached to a session), and the childCategoryies assoication has cascade save enabled. Hence, this code results in the new laptops category becoming persistent when tx.commit() is called, because Hibernate cascades the dirty-checking operation to the children of computer. Hibrnate executes an insert statement
Association cascade styles ,[object Object],[object Object],Category computer = …. // Loaded in a previous session Category laptops = new Category(“Laptops”); computer.getChildCategories().add(laptops); laptops.setParentCategory(computer); The detached computer object and any other detached objects it refers to are now associated with the new transient laptops object(and vice versa).
Association cascade styles ,[object Object],[object Object],[object Object],[object Object],[object Object],Session session = sessions.openSession(); Transaction tx = session.beginTransaction(); //persist one new category and the link to its parent category session.save(laptops); tx.commit(); session.close();
Automatic save or update for detached object graphs ,[object Object],[object Object],[object Object],Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); // Let Hibernate decide whats new and whats detached session.saveOrUpdate(theRootObjectOfGraph); tx.commit(); session.close();
Detecting transient instances ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],<class name=&quot;Category&quot; table=&quot;CATEGORY&quot;> <!-- null is the default, '0' is for primitive types --> <id name=&quot;id&quot;  unsaved-value=&quot;0&quot; > <generator class=&quot;native&quot;/> </id> .... </class>

Contenu connexe

Tendances

JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring DataArturs Drozdovs
 
Powerful persistence layer with Google Guice & MyBatis
Powerful persistence layer with Google Guice & MyBatisPowerful persistence layer with Google Guice & MyBatis
Powerful persistence layer with Google Guice & MyBatissimonetripodi
 
130919 jim cordy - when is a clone not a clone
130919   jim cordy - when is a clone not a clone130919   jim cordy - when is a clone not a clone
130919 jim cordy - when is a clone not a clonePtidej Team
 
Android Jetpack: ViewModel and Testing
Android Jetpack: ViewModel and TestingAndroid Jetpack: ViewModel and Testing
Android Jetpack: ViewModel and TestingYongjun Kim
 
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 exploitsPriyanka Aash
 
White Paper On ConCurrency For PCMS Application Architecture
White Paper On ConCurrency For PCMS Application ArchitectureWhite Paper On ConCurrency For PCMS Application Architecture
White Paper On ConCurrency For PCMS Application ArchitectureShahzad
 
MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...
MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...
MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...Otávio Santana
 
To Study The Tips Tricks Guidelines Related To Performance Tuning For N Hib...
To Study The Tips Tricks  Guidelines Related To Performance Tuning For  N Hib...To Study The Tips Tricks  Guidelines Related To Performance Tuning For  N Hib...
To Study The Tips Tricks Guidelines Related To Performance Tuning For N Hib...Shahzad
 
Java Concurrency Idioms
Java Concurrency IdiomsJava Concurrency Idioms
Java Concurrency IdiomsAlex Miller
 
OR Mapping- nhibernate Presentation
OR Mapping- nhibernate PresentationOR Mapping- nhibernate Presentation
OR Mapping- nhibernate PresentationShahzad
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency GotchasAlex Miller
 
Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Trainingsourabh aggarwal
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency GotchasAlex Miller
 
Architecture Components
Architecture Components Architecture Components
Architecture Components DataArt
 

Tendances (18)

JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring Data
 
Simple Jdbc With Spring 2.5
Simple Jdbc With Spring 2.5Simple Jdbc With Spring 2.5
Simple Jdbc With Spring 2.5
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Powerful persistence layer with Google Guice & MyBatis
Powerful persistence layer with Google Guice & MyBatisPowerful persistence layer with Google Guice & MyBatis
Powerful persistence layer with Google Guice & MyBatis
 
130919 jim cordy - when is a clone not a clone
130919   jim cordy - when is a clone not a clone130919   jim cordy - when is a clone not a clone
130919 jim cordy - when is a clone not a clone
 
Android Jetpack: ViewModel and Testing
Android Jetpack: ViewModel and TestingAndroid Jetpack: ViewModel and Testing
Android Jetpack: ViewModel and Testing
 
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
 
White Paper On ConCurrency For PCMS Application Architecture
White Paper On ConCurrency For PCMS Application ArchitectureWhite Paper On ConCurrency For PCMS Application Architecture
White Paper On ConCurrency For PCMS Application Architecture
 
MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...
MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...
MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...
 
To Study The Tips Tricks Guidelines Related To Performance Tuning For N Hib...
To Study The Tips Tricks  Guidelines Related To Performance Tuning For  N Hib...To Study The Tips Tricks  Guidelines Related To Performance Tuning For  N Hib...
To Study The Tips Tricks Guidelines Related To Performance Tuning For N Hib...
 
Java Concurrency Idioms
Java Concurrency IdiomsJava Concurrency Idioms
Java Concurrency Idioms
 
OR Mapping- nhibernate Presentation
OR Mapping- nhibernate PresentationOR Mapping- nhibernate Presentation
OR Mapping- nhibernate Presentation
 
Java
JavaJava
Java
 
JPA Best Practices
JPA Best PracticesJPA Best Practices
JPA Best Practices
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
 
Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Training
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
 
Architecture Components
Architecture Components Architecture Components
Architecture Components
 

En vedette

Ahmaddiya Guzette May jun2014 english-section
Ahmaddiya Guzette May jun2014 english-sectionAhmaddiya Guzette May jun2014 english-section
Ahmaddiya Guzette May jun2014 english-sectionmuzaffertahir9
 
Dear Son Dear Daughter
Dear Son Dear DaughterDear Son Dear Daughter
Dear Son Dear DaughterRanjan Kumar
 
Enigmatic And Wonderful Krasnoyarsk
Enigmatic And Wonderful KrasnoyarskEnigmatic And Wonderful Krasnoyarsk
Enigmatic And Wonderful KrasnoyarskOlga borodina
 
Population Ecology
Population EcologyPopulation Ecology
Population Ecologybill_wallace
 
Best Aviation Photography
Best Aviation PhotographyBest Aviation Photography
Best Aviation PhotographyRanjan Kumar
 
Extreme weather project
Extreme weather projectExtreme weather project
Extreme weather projectgvinyals
 

En vedette (8)

Ahmaddiya Guzette May jun2014 english-section
Ahmaddiya Guzette May jun2014 english-sectionAhmaddiya Guzette May jun2014 english-section
Ahmaddiya Guzette May jun2014 english-section
 
Dear Son Dear Daughter
Dear Son Dear DaughterDear Son Dear Daughter
Dear Son Dear Daughter
 
Sharks
SharksSharks
Sharks
 
Lillian
LillianLillian
Lillian
 
Enigmatic And Wonderful Krasnoyarsk
Enigmatic And Wonderful KrasnoyarskEnigmatic And Wonderful Krasnoyarsk
Enigmatic And Wonderful Krasnoyarsk
 
Population Ecology
Population EcologyPopulation Ecology
Population Ecology
 
Best Aviation Photography
Best Aviation PhotographyBest Aviation Photography
Best Aviation Photography
 
Extreme weather project
Extreme weather projectExtreme weather project
Extreme weather project
 

Similaire à 04 Data Access

09 Application Design
09 Application Design09 Application Design
09 Application DesignRanjan Kumar
 
02 Hibernate Introduction
02 Hibernate Introduction02 Hibernate Introduction
02 Hibernate IntroductionRanjan Kumar
 
Hibernate An Introduction
Hibernate An IntroductionHibernate An Introduction
Hibernate An IntroductionNguyen Cao
 
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 & STMMario Fusco
 
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)Paco de la Cruz
 
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2Leonid Maslov
 
Dynamic data race detection in concurrent Java programs
Dynamic data race detection in concurrent Java programsDynamic data race detection in concurrent Java programs
Dynamic data race detection in concurrent Java programsDevexperts
 
Jpa buenas practicas
Jpa buenas practicasJpa buenas practicas
Jpa buenas practicasfernellc
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksMongoDB
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade ServerlessKatyShimizu
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade ServerlessKatyShimizu
 
Drd secr final1_3
Drd secr final1_3Drd secr final1_3
Drd secr final1_3Devexperts
 
Diving in the Flex Data Binding Waters
Diving in the Flex Data Binding WatersDiving in the Flex Data Binding Waters
Diving in the Flex Data Binding Watersmichael.labriola
 
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.pptDESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.pptAntoJoseph36
 

Similaire à 04 Data Access (20)

09 Application Design
09 Application Design09 Application Design
09 Application Design
 
02 Hibernate Introduction
02 Hibernate Introduction02 Hibernate Introduction
02 Hibernate Introduction
 
Hibernate An Introduction
Hibernate An IntroductionHibernate An Introduction
Hibernate An Introduction
 
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
 
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)
 
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2
 
Dynamic data race detection in concurrent Java programs
Dynamic data race detection in concurrent Java programsDynamic data race detection in concurrent Java programs
Dynamic data race detection in concurrent Java programs
 
Jpa buenas practicas
Jpa buenas practicasJpa buenas practicas
Jpa buenas practicas
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
 
Hibernate
HibernateHibernate
Hibernate
 
Drd secr final1_3
Drd secr final1_3Drd secr final1_3
Drd secr final1_3
 
Hibernate
HibernateHibernate
Hibernate
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Diving in the Flex Data Binding Waters
Diving in the Flex Data Binding WatersDiving in the Flex Data Binding Waters
Diving in the Flex Data Binding Waters
 
jQuery
jQueryjQuery
jQuery
 
Drools
DroolsDrools
Drools
 
EJB Clients
EJB ClientsEJB Clients
EJB Clients
 
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.pptDESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
 

Plus de Ranjan Kumar

Plus de Ranjan Kumar (20)

Introduction to java ee
Introduction to java eeIntroduction to java ee
Introduction to java ee
 
Fantastic life views ons
Fantastic life views  onsFantastic life views  ons
Fantastic life views ons
 
Lessons on Life
Lessons on LifeLessons on Life
Lessons on Life
 
Story does not End here
Story does not End hereStory does not End here
Story does not End here
 
Whata Split Second Looks Like
Whata Split Second Looks LikeWhata Split Second Looks Like
Whata Split Second Looks Like
 
Friendship so Sweet
Friendship so SweetFriendship so Sweet
Friendship so Sweet
 
Dedicate Time
Dedicate TimeDedicate Time
Dedicate Time
 
Paradise on Earth
Paradise on EarthParadise on Earth
Paradise on Earth
 
Bolivian Highway
Bolivian HighwayBolivian Highway
Bolivian Highway
 
Chinese Proverb
Chinese ProverbChinese Proverb
Chinese Proverb
 
Warren Buffet
Warren BuffetWarren Buffet
Warren Buffet
 
Jara Sochiye
Jara SochiyeJara Sochiye
Jara Sochiye
 
Blue Beauty
Blue BeautyBlue Beauty
Blue Beauty
 
Alaska Railway Routes
Alaska Railway RoutesAlaska Railway Routes
Alaska Railway Routes
 
Poison that Kills the Dreams
Poison that Kills the DreamsPoison that Kills the Dreams
Poison that Kills the Dreams
 
Horrible Jobs
Horrible JobsHorrible Jobs
Horrible Jobs
 
Role of Attitude
Role of AttitudeRole of Attitude
Role of Attitude
 
45 Lesons in Life
45 Lesons in Life45 Lesons in Life
45 Lesons in Life
 
Easy Difficult
Easy DifficultEasy Difficult
Easy Difficult
 
7 cup of coffee
7 cup of coffee7 cup of coffee
7 cup of coffee
 

Dernier

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 

Dernier (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 

04 Data Access

  • 1. Data Access with Hibernate Persistent objects and persistence contexts
  • 2. Object state transitions and Session methods Transient Persistent Detached new garbage garbage delete() save() saveOrUpdate() get() load() find() iterate() etc. evict() close()* clear()* update() saveOrUpdate() lock() * affects all instances in a Session
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. The Hibernate identity scope Session session1 = sf.openSession(); Transaction tx1 = session.beginTransaction(); Object a = session1.load(Category.class, new Long(1234) ); Object b = session1.load(Category.class, new Long(1234) ); if ( a == b ) System.out.println(&quot;a and b are identicial and the same database identity.&quot;); tx1.commit(); session1.close(); Session session2 = sf.openSession(); Transaction tx2 = session.beginTransaction(); Object b2 = session2.load(Category.class, new Long(1234) ); if ( a != b2 ) System.out.println(&quot;a and b2 are not identical.&quot;); tx2.commit(); session2.close();
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22. Adding a new category to object graph Computer: Category Laptops : Category Electronics: Category Cell Phones: Category Desktop PCs: Category Monitors: Category
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.