SlideShare a Scribd company logo
1 of 19
Download to read offline
HIBERNATE VS. IBATIS
OR TWO WAYS OF DATABASE ACCESS




BOŠTJAN DOLENC, MARAND INŽENIRING
WHAT WE'RE ABOUT TO SEE:

  •   A bit about relevancy
  •   The ORM way (with Hibernate examples)
  •   The JDBC+ way (with iBatis examples)
  •   Problems
  •   Crossing the chasm
  •   Discussion (time permitting)
RELEVANCY

 • Data matters more than code
 • JDBC sucks
     – Aimde at system development
     – Lacks higher level features: statement
       manipulation, encapsulation, caching
     – Cumbersome use
 • Objects ≠ Relations (holy war)
ORM WAY

 • Object/class centric approach
 • Strict Object-Relational Mapping
   or
   “I hate bloody SQL”
 • Using Hibernate 3.x (and JDK <1.5)
ORM EXAMPLE
ORM EXAMPLE - CONTINUED
JDBC+ WAY

 • SQL centric approach
 • Improved JDBC
   or
   “Ad-hoc queries without JDBC horrors”
JDBC+ EXAMPLE
JDBC+ EXAMPLE - CONTINUED
ORM PROBLEM: 1+N FETCHING


 1
 2
                   10       1
                   11       1
                                42   10
                   12       1
                                43   11
                   13       2
                                44   11   22    42
                                45   12   23    42
                                46   13   ...   ...
ORM PROBLEM: 1+N FETCHING - CONTINUED

  • Eager loading to the rescue:
     – Next-level-only fails in deep hierarchies
     – All-levels fails when accessing only top-level
  • HQL to the rescue:
     – from Customer c
         join c.contracts co
         join co.bundles b
         join b.services s
ORM PROBLEM: MASSIVE UPDATES

                          for (ServiceTimeline st : services)
                          {
                            if (st.getValidTo() == null)
     1   1.1.               {
                              st.setValidTo(newDate);
     2   1.2.     1.12.
                            }
     3   15.10.           }
     4   1.2.

     5   1.1      1.12.   update service_timeline set valid_to =
                          #newDate# where valid_to is null
OTHER ORM PROBLEMS:

 • xQL (HQL, JP QL) ≠ SQL
     – Tools
     – Limited to programmers
 • POJOs sometimes aren’t Plain and Old
     – Common base class, proxies, code
       generation, annotations...
     – Build/startup overhead, subtle reflection bugs
JDBC+ PROBLEM: LOTS OF WORK FOR SIMPLE THINGS
JDBC+ PROBLEM: LOTS OF WORK FOR SIMPLE THINGS - CONTINUED
JDBC+ PROBLEM: MANUAL SAVING (INSERT/UPDATE) IS TEDIOUS


 1
               1
 2
                    10     1        2

                    11     1                         3
                                        42   10
                    12     1
                                        43   11      4
                    13     2
                                        44   11      5    22    42
                                        45   12           23    42
                                        46   13           ...   ...
OTHER JDBC+ PROBLEMS:

 • Limited caching
     – Caches only query results (by definition)
     – ORM can “understand” mutations, JDBC+
       can’t
 • Fear of SQL
     – People problem
     – Training and tools help a lot
MIX APPROACHES TO CROSS THE CHASM:

  From ORM toward JDBC+              From JDBC+ toward ORM

  • Eager flushing                   • Save phase at the end
  • HQL, SQL queries                 • Get-by-id, update, insert,
                                       delete for each class
  • Form-based / non-generic         • Active Record-like DAOs,
    development                        reflection + dynamic SQL
  • Discipline, examine the          • Custom development
    inner workings
CONCLUSION

 • The ORM-SQL chasm might be scary
 • It’s not that wide
 • You can stay in the middle with some
   tricks

More Related Content

Viewers also liked

Viewers also liked (6)

Struts presentation
Struts presentationStruts presentation
Struts presentation
 
Struts introduction
Struts introductionStruts introduction
Struts introduction
 
JSP Custom Tags
JSP Custom TagsJSP Custom Tags
JSP Custom Tags
 
Introduction to Struts 1.3
Introduction to Struts 1.3Introduction to Struts 1.3
Introduction to Struts 1.3
 
WebLogic Deployment Plan Example
WebLogic Deployment Plan ExampleWebLogic Deployment Plan Example
WebLogic Deployment Plan Example
 
Introducing Swagger
Introducing SwaggerIntroducing Swagger
Introducing Swagger
 

Similar to [Dolenc] Hibernate vs. iBatis

Brian Oliver Pimp My Data Grid
Brian Oliver  Pimp My Data GridBrian Oliver  Pimp My Data Grid
Brian Oliver Pimp My Data Griddeimos
 
Introducing LCS to Digital Design Verification
Introducing LCS to Digital Design VerificationIntroducing LCS to Digital Design Verification
Introducing LCS to Digital Design VerificationDaniele Loiacono
 
BADCamp 2008 DB Sync
BADCamp 2008 DB SyncBADCamp 2008 DB Sync
BADCamp 2008 DB SyncShaun Haber
 
Challenges with MongoDB
Challenges with MongoDBChallenges with MongoDB
Challenges with MongoDBStone Gao
 
Nagios Conference 2012 - Mike Weber - disaster
Nagios Conference 2012 - Mike Weber - disasterNagios Conference 2012 - Mike Weber - disaster
Nagios Conference 2012 - Mike Weber - disasterNagios
 
Shared Database Concurrency
Shared Database ConcurrencyShared Database Concurrency
Shared Database ConcurrencyAivars Kalvans
 
Monitoring and troubleshooting a glideinWMS-based HTCondor pool
Monitoring and troubleshooting a glideinWMS-based HTCondor poolMonitoring and troubleshooting a glideinWMS-based HTCondor pool
Monitoring and troubleshooting a glideinWMS-based HTCondor poolIgor Sfiligoi
 
Stop (de)bugging me - ICON UK 2013
Stop (de)bugging me - ICON UK 2013Stop (de)bugging me - ICON UK 2013
Stop (de)bugging me - ICON UK 2013Mark Leusink
 
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...Steve Lange
 
Coredns nodecache - A highly-available Node-cache DNS server
Coredns nodecache - A highly-available Node-cache DNS serverCoredns nodecache - A highly-available Node-cache DNS server
Coredns nodecache - A highly-available Node-cache DNS serverYann Hamon
 
Five Lessons in Distributed Databases
Five Lessons  in Distributed DatabasesFive Lessons  in Distributed Databases
Five Lessons in Distributed Databasesjbellis
 
Nagios Conference 2012 - Nathan Vonnahme - Monitoring the User Experience
Nagios Conference 2012 - Nathan Vonnahme - Monitoring the User ExperienceNagios Conference 2012 - Nathan Vonnahme - Monitoring the User Experience
Nagios Conference 2012 - Nathan Vonnahme - Monitoring the User ExperienceNagios
 
TROUBLESHOOTING ENTERPRISE GEODATABASE TOOLS
TROUBLESHOOTING ENTERPRISE GEODATABASE TOOLSTROUBLESHOOTING ENTERPRISE GEODATABASE TOOLS
TROUBLESHOOTING ENTERPRISE GEODATABASE TOOLSstmgonzalezro
 
Grokking Techtalk #37: Data intensive problem
 Grokking Techtalk #37: Data intensive problem Grokking Techtalk #37: Data intensive problem
Grokking Techtalk #37: Data intensive problemGrokking VN
 
Improving Operational Space Responsiveness
Improving Operational Space ResponsivenessImproving Operational Space Responsiveness
Improving Operational Space ResponsivenessPat Cappelaere
 
Multi Core Playground
Multi Core PlaygroundMulti Core Playground
Multi Core PlaygroundESUG
 
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
Just In Time Scalability  Agile Methods To Support Massive Growth PresentationJust In Time Scalability  Agile Methods To Support Massive Growth Presentation
Just In Time Scalability Agile Methods To Support Massive Growth PresentationLong Nguyen
 

Similar to [Dolenc] Hibernate vs. iBatis (20)

Brian Oliver Pimp My Data Grid
Brian Oliver  Pimp My Data GridBrian Oliver  Pimp My Data Grid
Brian Oliver Pimp My Data Grid
 
Introducing LCS to Digital Design Verification
Introducing LCS to Digital Design VerificationIntroducing LCS to Digital Design Verification
Introducing LCS to Digital Design Verification
 
Redis ndc2013
Redis ndc2013Redis ndc2013
Redis ndc2013
 
BADCamp 2008 DB Sync
BADCamp 2008 DB SyncBADCamp 2008 DB Sync
BADCamp 2008 DB Sync
 
Challenges with MongoDB
Challenges with MongoDBChallenges with MongoDB
Challenges with MongoDB
 
Nagios Conference 2012 - Mike Weber - disaster
Nagios Conference 2012 - Mike Weber - disasterNagios Conference 2012 - Mike Weber - disaster
Nagios Conference 2012 - Mike Weber - disaster
 
Shared Database Concurrency
Shared Database ConcurrencyShared Database Concurrency
Shared Database Concurrency
 
Monitoring and troubleshooting a glideinWMS-based HTCondor pool
Monitoring and troubleshooting a glideinWMS-based HTCondor poolMonitoring and troubleshooting a glideinWMS-based HTCondor pool
Monitoring and troubleshooting a glideinWMS-based HTCondor pool
 
Stop (de)bugging me - ICON UK 2013
Stop (de)bugging me - ICON UK 2013Stop (de)bugging me - ICON UK 2013
Stop (de)bugging me - ICON UK 2013
 
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
 
Coredns nodecache - A highly-available Node-cache DNS server
Coredns nodecache - A highly-available Node-cache DNS serverCoredns nodecache - A highly-available Node-cache DNS server
Coredns nodecache - A highly-available Node-cache DNS server
 
Five Lessons in Distributed Databases
Five Lessons  in Distributed DatabasesFive Lessons  in Distributed Databases
Five Lessons in Distributed Databases
 
Nagios Conference 2012 - Nathan Vonnahme - Monitoring the User Experience
Nagios Conference 2012 - Nathan Vonnahme - Monitoring the User ExperienceNagios Conference 2012 - Nathan Vonnahme - Monitoring the User Experience
Nagios Conference 2012 - Nathan Vonnahme - Monitoring the User Experience
 
TROUBLESHOOTING ENTERPRISE GEODATABASE TOOLS
TROUBLESHOOTING ENTERPRISE GEODATABASE TOOLSTROUBLESHOOTING ENTERPRISE GEODATABASE TOOLS
TROUBLESHOOTING ENTERPRISE GEODATABASE TOOLS
 
Advanced Deployment
Advanced DeploymentAdvanced Deployment
Advanced Deployment
 
Grokking Techtalk #37: Data intensive problem
 Grokking Techtalk #37: Data intensive problem Grokking Techtalk #37: Data intensive problem
Grokking Techtalk #37: Data intensive problem
 
Improving Operational Space Responsiveness
Improving Operational Space ResponsivenessImproving Operational Space Responsiveness
Improving Operational Space Responsiveness
 
An Hour of DB2 Tips
An Hour of DB2 TipsAn Hour of DB2 Tips
An Hour of DB2 Tips
 
Multi Core Playground
Multi Core PlaygroundMulti Core Playground
Multi Core Playground
 
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
Just In Time Scalability  Agile Methods To Support Massive Growth PresentationJust In Time Scalability  Agile Methods To Support Massive Growth Presentation
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
 

More from javablend

[Muir] Seam 2 in practice
[Muir] Seam 2 in practice[Muir] Seam 2 in practice
[Muir] Seam 2 in practicejavablend
 
[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cool[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cooljavablend
 
[Roblek] Distributed computing in practice
[Roblek] Distributed computing in practice[Roblek] Distributed computing in practice
[Roblek] Distributed computing in practicejavablend
 
[Hajdukovic] Developing J2ME games for mobile phones
[Hajdukovic] Developing J2ME games for mobile phones[Hajdukovic] Developing J2ME games for mobile phones
[Hajdukovic] Developing J2ME games for mobile phonesjavablend
 
[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application
[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application
[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your applicationjavablend
 
[Turk] Going native with Tomcat
[Turk] Going native with Tomcat[Turk] Going native with Tomcat
[Turk] Going native with Tomcatjavablend
 
[Grabec] Solr - Searching made easy
[Grabec] Solr - Searching made easy[Grabec] Solr - Searching made easy
[Grabec] Solr - Searching made easyjavablend
 

More from javablend (7)

[Muir] Seam 2 in practice
[Muir] Seam 2 in practice[Muir] Seam 2 in practice
[Muir] Seam 2 in practice
 
[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cool[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cool
 
[Roblek] Distributed computing in practice
[Roblek] Distributed computing in practice[Roblek] Distributed computing in practice
[Roblek] Distributed computing in practice
 
[Hajdukovic] Developing J2ME games for mobile phones
[Hajdukovic] Developing J2ME games for mobile phones[Hajdukovic] Developing J2ME games for mobile phones
[Hajdukovic] Developing J2ME games for mobile phones
 
[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application
[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application
[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application
 
[Turk] Going native with Tomcat
[Turk] Going native with Tomcat[Turk] Going native with Tomcat
[Turk] Going native with Tomcat
 
[Grabec] Solr - Searching made easy
[Grabec] Solr - Searching made easy[Grabec] Solr - Searching made easy
[Grabec] Solr - Searching made easy
 

Recently uploaded

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 Nanonetsnaman860154
 
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...Neo4j
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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 Servicegiselly40
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
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 DevelopmentsTrustArc
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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 2024Rafal Los
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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.pdfsudhanshuwaghmare1
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 

Recently uploaded (20)

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
 
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...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

[Dolenc] Hibernate vs. iBatis

  • 1. HIBERNATE VS. IBATIS OR TWO WAYS OF DATABASE ACCESS BOŠTJAN DOLENC, MARAND INŽENIRING
  • 2. WHAT WE'RE ABOUT TO SEE: • A bit about relevancy • The ORM way (with Hibernate examples) • The JDBC+ way (with iBatis examples) • Problems • Crossing the chasm • Discussion (time permitting)
  • 3. RELEVANCY • Data matters more than code • JDBC sucks – Aimde at system development – Lacks higher level features: statement manipulation, encapsulation, caching – Cumbersome use • Objects ≠ Relations (holy war)
  • 4. ORM WAY • Object/class centric approach • Strict Object-Relational Mapping or “I hate bloody SQL” • Using Hibernate 3.x (and JDK <1.5)
  • 6. ORM EXAMPLE - CONTINUED
  • 7. JDBC+ WAY • SQL centric approach • Improved JDBC or “Ad-hoc queries without JDBC horrors”
  • 9. JDBC+ EXAMPLE - CONTINUED
  • 10. ORM PROBLEM: 1+N FETCHING 1 2 10 1 11 1 42 10 12 1 43 11 13 2 44 11 22 42 45 12 23 42 46 13 ... ...
  • 11. ORM PROBLEM: 1+N FETCHING - CONTINUED • Eager loading to the rescue: – Next-level-only fails in deep hierarchies – All-levels fails when accessing only top-level • HQL to the rescue: – from Customer c join c.contracts co join co.bundles b join b.services s
  • 12. ORM PROBLEM: MASSIVE UPDATES for (ServiceTimeline st : services) { if (st.getValidTo() == null) 1 1.1. { st.setValidTo(newDate); 2 1.2. 1.12. } 3 15.10. } 4 1.2. 5 1.1 1.12. update service_timeline set valid_to = #newDate# where valid_to is null
  • 13. OTHER ORM PROBLEMS: • xQL (HQL, JP QL) ≠ SQL – Tools – Limited to programmers • POJOs sometimes aren’t Plain and Old – Common base class, proxies, code generation, annotations... – Build/startup overhead, subtle reflection bugs
  • 14. JDBC+ PROBLEM: LOTS OF WORK FOR SIMPLE THINGS
  • 15. JDBC+ PROBLEM: LOTS OF WORK FOR SIMPLE THINGS - CONTINUED
  • 16. JDBC+ PROBLEM: MANUAL SAVING (INSERT/UPDATE) IS TEDIOUS 1 1 2 10 1 2 11 1 3 42 10 12 1 43 11 4 13 2 44 11 5 22 42 45 12 23 42 46 13 ... ...
  • 17. OTHER JDBC+ PROBLEMS: • Limited caching – Caches only query results (by definition) – ORM can “understand” mutations, JDBC+ can’t • Fear of SQL – People problem – Training and tools help a lot
  • 18. MIX APPROACHES TO CROSS THE CHASM: From ORM toward JDBC+ From JDBC+ toward ORM • Eager flushing • Save phase at the end • HQL, SQL queries • Get-by-id, update, insert, delete for each class • Form-based / non-generic • Active Record-like DAOs, development reflection + dynamic SQL • Discipline, examine the • Custom development inner workings
  • 19. CONCLUSION • The ORM-SQL chasm might be scary • It’s not that wide • You can stay in the middle with some tricks