The document introduces object-relational mapping (ORM) frameworks, which help bridge the gap between object-oriented programming and relational databases by mapping objects to database tables. It discusses some of the key concepts in ORM frameworks like mapping object-oriented concepts like inheritance and composition to relational database schemas. Finally, it outlines some of the benefits of using ORM frameworks like increased productivity through object-oriented programming and improved performance through features like lazy loading and caching.
3. Procedural Vs. OO
• Procedures are core • Objects are core
entities entities
• Data exist to feed • Objects consist of
procedures execution function and data at the
• Workflow relation same level
between procedures • Rich OO relation:
– Composition
– Inheritance
– Workflow
– …
13. OR Impedance Mismatch, Cont.
• Moving objects between OO and RDB worlds
• Load on demand
• Trace and update
• Identity
14. OR Impedance Mismatch, Cont.
• RDB does not support OO concepts
immediately:
• Inheritance
• Complex, non-normalized composition
• Encapsulation and Interface
15. OR Impedance Mismatch, Cont.
• Who
• Outlive the other?
• Is more expensive?
• Is master/slave?
16. So Why Still RDB?
• High performance,
Powerful
• Available, Everywhere
• Proven
– in theory
– and in practice
• Known in every language
• Almost no dominate
replacement
17. Solution
• RDB+SQL:
• JDBC (no solution!)
• RDB+ORM:
• Hibernate (OSS, JBoss, supports EJB3)
• JDO
• EJB3
(JDBC/EJB3/JDO JCP Spec, supported by Sun, IBM, Oracle, JBoss and other Java friends.)
• RDB, SQL mapping:
• iBATIS (IBM Prod.)
• OODB:
• Db4o (OSS, Recent years tries hard
to prove itself! Not dominate yet!)
19. ORM, Mapping OO Concepts to RDB Concepts
• Inheritance
– Table per Hierarchy
– Lost Memory
– No Modularity
– Table per Class
– Join, lost time
– Table per Concrete Class
– Redundancy
21. ORM, Relationship Navigation
• Lazy Loading
• Delay loading ‘e’ if it’s rare to load ‘b’ if ‘e’ is loaded
• Avoid memory waste for unnecessary objects
• Eager Loading
• Load ‘b’ with ‘e’ if it’s common to load ‘b’ if ‘e’ is loaded
• Avoid delays for loading objects
22. ORM, Trace, Update, Identities
• Trace loaded objects
• Preserve relation between objects and
corresponding RDB data
• Return same object for request for same data
• Apply changes to object to same data in RDB
• Knows which object should be update
23. ORM, Query Language, CRUD API
• Create, Read, Update, Delete Objects
in/from/to RDB
• Query lang for search for objects stored in
RDB
• Support SQL, convert SQL result to objects
24. ORM, Transparency
• Domain model objects should act as if they
are not persistence object
• Use Repository interfaces and implementation
to talk to ORM framework
25. ORM, Transaction
• An API to do atomic jobs
startTransaction();
…
If( everyThingIsOk){
commit();
}else{
rollback();
}
26. ORM, Caching
• Cache loaded objects even if they are not
needed any more to benefit from request
for them in near future
28. When SQL?
• Performance
• Handwritten SQLs
• Special SQL queries
• Special RDBMS features
• Limited SQL
• Organization policy or DBA
• Legacy RDBMSs or RDBs
• No OO, i.e. Procedural style
• Create an ORM framework