[Dolenc] Hibernate vs. iBatis
Click here to load reader
-
Upload
javablend -
Category
Technology
-
view
3.511 -
download
2
Transcript of [Dolenc] Hibernate vs. iBatis
![Page 1: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/1.jpg)
HIBERNATE VS. IBATIS
OR TWO WAYS OF DATABASE ACCESS
BOŠTJAN DOLENC, MARAND INŽENIRING
![Page 2: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/2.jpg)
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)
![Page 3: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/3.jpg)
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)
![Page 4: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/4.jpg)
ORM WAY
• Object/class centric approach
• Strict Object-Relational Mapping
or
“I hate bloody SQL”
• Using Hibernate 3.x (and JDK <1.5)
![Page 5: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/5.jpg)
ORM EXAMPLE
![Page 6: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/6.jpg)
ORM EXAMPLE - CONTINUED
![Page 7: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/7.jpg)
JDBC+ WAY
• SQL centric approach
• Improved JDBC
or
“Ad-hoc queries without JDBC horrors”
![Page 8: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/8.jpg)
JDBC+ EXAMPLE
![Page 9: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/9.jpg)
JDBC+ EXAMPLE - CONTINUED
![Page 10: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/10.jpg)
ORM PROBLEM: 1+N FETCHING
1
2
10 1
11 1
12 1
13 2
42 10
43 11
44 11
45 12
46 13
22 42
23 42
... ...
![Page 11: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/11.jpg)
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
![Page 12: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/12.jpg)
ORM PROBLEM: MASSIVE UPDATES
1 1.1.
2 1.2. 1.12.
3 15.10.
4 1.2.
5 1.1 1.12.
for (ServiceTimeline st : services)
{
if (st.getValidTo() == null)
{
st.setValidTo(newDate);
}
}
update service_timeline set valid_to =
#newDate# where valid_to is null
![Page 13: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/13.jpg)
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
![Page 14: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/14.jpg)
JDBC+ PROBLEM: LOTS OF WORK FOR SIMPLE THINGS
![Page 15: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/15.jpg)
JDBC+ PROBLEM: LOTS OF WORK FOR SIMPLE THINGS - CONTINUED
![Page 16: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/16.jpg)
JDBC+ PROBLEM: MANUAL SAVING (INSERT/UPDATE) IS TEDIOUS
1
2
10 1
11 1
12 1
13 2
42 10
43 11
44 11
45 12
46 13
22 42
23 42
... ...
1
2
3
4
5
![Page 17: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/17.jpg)
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
![Page 18: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/18.jpg)
MIX APPROACHES TO CROSS THE CHASM:
From ORM toward JDBC+
• Eager flushing
• HQL, SQL queries
• Form-based / non-generic
development
• Discipline, examine the
inner workings
From JDBC+ toward ORM
• Save phase at the end
• Get-by-id, update, insert,
delete for each class
• Active Record-like DAOs,
reflection + dynamic SQL
• Custom development
![Page 19: [Dolenc] Hibernate vs. iBatis](https://reader038.fdocuments.in/reader038/viewer/2022100606/559e9f311a28abc7048b4794/html5/thumbnails/19.jpg)
CONCLUSION
• The ORM-SQL chasm might be scary
• It’s not that wide
• You can stay in the middle with some
tricks