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)
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
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