SlideShare une entreprise Scribd logo
1  sur  33
Introduction To ORM Frameworks

          Ali Shakiba
Procedural Vs. OO
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
                            –   …
Object Oriented Concepts

• Class & Object
Object Oriented Concepts, Cont.

• Data (fields, properties, state, attributes)
• Function (methods, procedures)
Object Oriented Concepts, Cont.

• Reference (pointer, link, complex objects
  graph)
Object Oriented Concepts, Cont.

• Encapsulation
  & Interfaces
Object Oriented Concepts, Cont.

• Inheritance & Specialization
Business Logic & Domain Model

• Business Logic: What should the software do?
• Domain Model: OO implementation of BL.
Relational Databases Concepts

•   Table & Tuple
•   Primary Key
•   Foreign Key
•   SQL Query
•   Normalization
•   Transaction
RDB Concepts, Cont.
Object-Relational Impedance Mismatch

• OO does not talk SQL
     • Lots of SQL for lots of objects
     • RDBMs’ dialect
     • Write/change/maintain nightmare
OR Impedance Mismatch, Cont.

• Moving objects between OO and RDB worlds
    • Load on demand
    • Trace and update
    • Identity
OR Impedance Mismatch, Cont.

• RDB does not support OO concepts
  immediately:
     • Inheritance
     • Complex, non-normalized composition
     • Encapsulation and Interface
OR Impedance Mismatch, Cont.

• Who
    • Outlive the other?
    • Is more expensive?
    • Is master/slave?
So Why Still RDB?
• High performance,
  Powerful
• Available, Everywhere
• Proven
  – in theory
  – and in practice
• Known in every language
• Almost no dominate
  replacement
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!)
ORM Features
• Mapping OO concepts to RDB concepts
• Relationship navigation
  – Eager/Lazy loading
• Trace & update changes
  – Lazy update
• Map identities
• Query language, CRUD API
• Transparency
• Transaction
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
ORM, Mapping OO Concepts to RDB Concepts, Cont.


• Composition
   – Collections (Indexed)
   – Value/Embedded Objects
• Bi-directional reference
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
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
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
ORM, Transparency

• Domain model objects should act as if they
  are not persistence object
• Use Repository interfaces and implementation
  to talk to ORM framework
ORM, Transaction

• An API to do atomic jobs
  startTransaction();
  …
  If( everyThingIsOk){
     commit();
  }else{
     rollback();
  }
ORM, Caching

•   Cache loaded objects even if they are not
    needed any more to benefit from request
    for them in near future
ORM Benefits

• Productivity
  – OOP
  – No SQL
• Performance
  – Cache Objects
  – Lazy/Eager Loading
  – Lazy Updating
• Portability
  – Different SQL dialects
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
Case Study: Simple Wiki
Case Study: Simple Wiki, Cont.
Case Study: Simple Wiki, Cont.
Case Study: Simple Wiki, Cont.
Case Study: Simple Wiki, Cont.

Contenu connexe

En vedette

Odoo - Business intelligence: Develop cube views for your own objects
Odoo - Business intelligence: Develop cube views for your own objectsOdoo - Business intelligence: Develop cube views for your own objects
Odoo - Business intelligence: Develop cube views for your own objectsOdoo
 
Object-Relational Mapping for Dummies
Object-Relational Mapping for DummiesObject-Relational Mapping for Dummies
Object-Relational Mapping for DummiesGlobalLogic Ukraine
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
Object Relational Mapping in PHP
Object Relational Mapping in PHPObject Relational Mapping in PHP
Object Relational Mapping in PHPRob Knight
 
JavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern ImplementationJavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern Implementationdavejohnson
 

En vedette (6)

Web service introduction
Web service introductionWeb service introduction
Web service introduction
 
Odoo - Business intelligence: Develop cube views for your own objects
Odoo - Business intelligence: Develop cube views for your own objectsOdoo - Business intelligence: Develop cube views for your own objects
Odoo - Business intelligence: Develop cube views for your own objects
 
Object-Relational Mapping for Dummies
Object-Relational Mapping for DummiesObject-Relational Mapping for Dummies
Object-Relational Mapping for Dummies
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Object Relational Mapping in PHP
Object Relational Mapping in PHPObject Relational Mapping in PHP
Object Relational Mapping in PHP
 
JavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern ImplementationJavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern Implementation
 

Similaire à Introduction to Object-Relational Mapping

ORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewBrett Meyer
 
hibernateormoverview-140501154227-phpapp02.pdf
hibernateormoverview-140501154227-phpapp02.pdfhibernateormoverview-140501154227-phpapp02.pdf
hibernateormoverview-140501154227-phpapp02.pdfPatiento Del Mar
 
2010 05-21, object-relational mapping using hibernate v2
2010 05-21, object-relational mapping using hibernate v22010 05-21, object-relational mapping using hibernate v2
2010 05-21, object-relational mapping using hibernate v2alvaro alcocer sotil
 
Advance Database Management Systems -Object Oriented Principles In Database
Advance Database Management Systems -Object Oriented Principles In DatabaseAdvance Database Management Systems -Object Oriented Principles In Database
Advance Database Management Systems -Object Oriented Principles In DatabaseSonali Parab
 
Data Modeling for NoSQL
Data Modeling for NoSQLData Modeling for NoSQL
Data Modeling for NoSQLTony Tam
 
The Rise of NoSQL and Polyglot Persistence
The Rise of NoSQL and Polyglot PersistenceThe Rise of NoSQL and Polyglot Persistence
The Rise of NoSQL and Polyglot PersistenceAbdelmonaim Remani
 
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...Lucas Jellema
 
Evolution of the Graph Schema
Evolution of the Graph SchemaEvolution of the Graph Schema
Evolution of the Graph SchemaJoshua Shinavier
 
hibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdfhibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdfPatiento Del Mar
 
From ddd to DDD : My journey from data-driven development to Domain-Driven De...
From ddd to DDD : My journey from data-driven development to Domain-Driven De...From ddd to DDD : My journey from data-driven development to Domain-Driven De...
From ddd to DDD : My journey from data-driven development to Domain-Driven De...Thibaud Desodt
 
Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)Don Demcsak
 
How to organize the business layer in software
How to organize the business layer in softwareHow to organize the business layer in software
How to organize the business layer in softwareArnaud LEMAIRE
 
Using JPA applications in the era of NoSQL: Introducing Hibernate OGM
Using JPA applications in the era of NoSQL: Introducing Hibernate OGMUsing JPA applications in the era of NoSQL: Introducing Hibernate OGM
Using JPA applications in the era of NoSQL: Introducing Hibernate OGMPT.JUG
 
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and CapabilitiesNot Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and CapabilitiesBrett Meyer
 
What is persistence in java
What is persistence in javaWhat is persistence in java
What is persistence in javaBenjamin Kim
 
Lviv EDGE 2 - NoSQL
Lviv EDGE 2 - NoSQLLviv EDGE 2 - NoSQL
Lviv EDGE 2 - NoSQLzenyk
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsJonas Bonér
 
[db tech showcase Tokyo 2016] E32: My Life as a Disruptor by Jim Starkey
[db tech showcase Tokyo 2016] E32: My Life as a Disruptor by Jim Starkey[db tech showcase Tokyo 2016] E32: My Life as a Disruptor by Jim Starkey
[db tech showcase Tokyo 2016] E32: My Life as a Disruptor by Jim StarkeyInsight Technology, Inc.
 

Similaire à Introduction to Object-Relational Mapping (20)

ORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate Overview
 
hibernateormoverview-140501154227-phpapp02.pdf
hibernateormoverview-140501154227-phpapp02.pdfhibernateormoverview-140501154227-phpapp02.pdf
hibernateormoverview-140501154227-phpapp02.pdf
 
ORM Methodology
ORM MethodologyORM Methodology
ORM Methodology
 
2010 05-21, object-relational mapping using hibernate v2
2010 05-21, object-relational mapping using hibernate v22010 05-21, object-relational mapping using hibernate v2
2010 05-21, object-relational mapping using hibernate v2
 
MongoDB
MongoDBMongoDB
MongoDB
 
Advance Database Management Systems -Object Oriented Principles In Database
Advance Database Management Systems -Object Oriented Principles In DatabaseAdvance Database Management Systems -Object Oriented Principles In Database
Advance Database Management Systems -Object Oriented Principles In Database
 
Data Modeling for NoSQL
Data Modeling for NoSQLData Modeling for NoSQL
Data Modeling for NoSQL
 
The Rise of NoSQL and Polyglot Persistence
The Rise of NoSQL and Polyglot PersistenceThe Rise of NoSQL and Polyglot Persistence
The Rise of NoSQL and Polyglot Persistence
 
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...
 
Evolution of the Graph Schema
Evolution of the Graph SchemaEvolution of the Graph Schema
Evolution of the Graph Schema
 
hibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdfhibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdf
 
From ddd to DDD : My journey from data-driven development to Domain-Driven De...
From ddd to DDD : My journey from data-driven development to Domain-Driven De...From ddd to DDD : My journey from data-driven development to Domain-Driven De...
From ddd to DDD : My journey from data-driven development to Domain-Driven De...
 
Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)
 
How to organize the business layer in software
How to organize the business layer in softwareHow to organize the business layer in software
How to organize the business layer in software
 
Using JPA applications in the era of NoSQL: Introducing Hibernate OGM
Using JPA applications in the era of NoSQL: Introducing Hibernate OGMUsing JPA applications in the era of NoSQL: Introducing Hibernate OGM
Using JPA applications in the era of NoSQL: Introducing Hibernate OGM
 
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and CapabilitiesNot Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
 
What is persistence in java
What is persistence in javaWhat is persistence in java
What is persistence in java
 
Lviv EDGE 2 - NoSQL
Lviv EDGE 2 - NoSQLLviv EDGE 2 - NoSQL
Lviv EDGE 2 - NoSQL
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability Patterns
 
[db tech showcase Tokyo 2016] E32: My Life as a Disruptor by Jim Starkey
[db tech showcase Tokyo 2016] E32: My Life as a Disruptor by Jim Starkey[db tech showcase Tokyo 2016] E32: My Life as a Disruptor by Jim Starkey
[db tech showcase Tokyo 2016] E32: My Life as a Disruptor by Jim Starkey
 

Introduction to Object-Relational Mapping

  • 1. Introduction To ORM Frameworks Ali Shakiba
  • 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 – …
  • 5. Object Oriented Concepts, Cont. • Data (fields, properties, state, attributes) • Function (methods, procedures)
  • 6. Object Oriented Concepts, Cont. • Reference (pointer, link, complex objects graph)
  • 7. Object Oriented Concepts, Cont. • Encapsulation & Interfaces
  • 8. Object Oriented Concepts, Cont. • Inheritance & Specialization
  • 9. Business Logic & Domain Model • Business Logic: What should the software do? • Domain Model: OO implementation of BL.
  • 10. Relational Databases Concepts • Table & Tuple • Primary Key • Foreign Key • SQL Query • Normalization • Transaction
  • 12. Object-Relational Impedance Mismatch • OO does not talk SQL • Lots of SQL for lots of objects • RDBMs’ dialect • Write/change/maintain nightmare
  • 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!)
  • 18. ORM Features • Mapping OO concepts to RDB concepts • Relationship navigation – Eager/Lazy loading • Trace & update changes – Lazy update • Map identities • Query language, CRUD API • Transparency • Transaction
  • 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
  • 20. ORM, Mapping OO Concepts to RDB Concepts, Cont. • Composition – Collections (Indexed) – Value/Embedded Objects • Bi-directional reference
  • 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
  • 27. ORM Benefits • Productivity – OOP – No SQL • Performance – Cache Objects – Lazy/Eager Loading – Lazy Updating • Portability – Different SQL dialects
  • 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
  • 30. Case Study: Simple Wiki, Cont.
  • 31. Case Study: Simple Wiki, Cont.
  • 32. Case Study: Simple Wiki, Cont.
  • 33. Case Study: Simple Wiki, Cont.