ORM Object-Relational Mapping 1. Object Persistence Persistence is the ability of an object to survive the lifecycle of the process, in which it resides.

Slides:



Advertisements
Similar presentations
Introduction to NHibernate By Andrew Smith. The Basics Object Relation Mapper Maps POCOs to database tables Based on Java Hibernate. V stable Generates.
Advertisements

An Object/Relational Mapping tool Free and open source Simplifies storage of object data in a relational database Removes the need to write and maintain.
Chapter 10: Designing Databases
Spring, Hibernate and Web Services 13 th September 2014.
Object-Oriented Databases v OO systems associated with – graphical user interface (GUI) – powerful modeling techniques – advanced data management capabilities.
Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar.
Geographic Information Systems
Designing a Database Unleashing the Power of Relational Database Design.
© 2005, Cornell University. Rapid Application Development using the Kuali Architecture (Struts, Spring and OJB) A Case Study Bryan Hutchinson
Fundamentals, Design, and Implementation, 9/e Chapter 16 Object-Oriented Database Processing.
Object-Oriented Methods: Database Technology An introduction.
Session-01. Hibernate Framework ? Why we use Hibernate ?
MS Access 2007 IT User Services - University of Delaware.
Data Persistence and Object-Relational Mapping Slides by James Brucker, used with his permission 1.
Data Access Patterns. Motivation Most software systems require persistent data (i.e. data that persists between program executions). In general, distributing.
Object Persistence and Object-Relational Mapping James Brucker.
Enterprise Object Framework. What is EOF? Enterprise Objects Framework is a set of tools and resources that help you create applications that work with.
Object and object-relational databases 1. Object databases vs. Object-relational databases Object databases Stores complex objects – Data + functions.
Chapter 24 Introduction to Object DBMSs Prepared by Kai Huang CS157B Prof Sin-Min Lee.
Data Access Patterns Some of the problems with data access from OO programs: 1.Data source and OO program use different data modelling concepts 2.Decoupling.
1 Overview of Databases. 2 Content Databases Example: Access Structure Query language (SQL)
NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27
Entity Beans BMP Celsina Bignoli
Introduction to SQL Steve Perry
CHAPTER 14 USING RELATIONAL DATABASES TO PROVIDE OBJECT PERSISTENCE (ONLINE) © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database.
Object-Oriented Database Management Systems (ODBMS)
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 4th Edition Copyright © 2009 John Wiley & Sons, Inc. All rights.
1 CS 430 Database Theory Winter 2005 Lecture 17: Objects, XML, and DBMSs.
Object-relational mapping Author: Jaroslav Orság Diploma thesis supervisor: Ing. Augustín Mrázik.
Object Oriented Analysis and Design 1 Chapter 7 Database Design  UML Specification for Data Modeling  The Relational Data Model and Object Model  Persistence.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
1 Part 2: EJB Persistency Jianguo Lu. 2 Object Persistency A persistent object is one that can automatically store and retrieve itself in permanent storage.
© 2011 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 14 Using Relational Databases to Provide Object Persistence (Overview) Modern Database.
Hibernate Persistence. What is Persistence Persist data to database or other storage.  In OO world, persistence means persist object to external storage.
A Simple Java Relational Database Thomas A. Bullinger March 20, 2001
JBoss at Work Databases and JBoss Chapter 4 Jeff Schmitt October 26, 2006.
Topic : Hibernate 2: Object Persistence and ORM Kaster Nurmukan.
Domain and Persistence Patterns. Fundamental Pattern Types Design Patterns Business Logic Patterns.
Object-Relational Mapping with Hibernate Brian Sam-Bodden Principal Partner Integrallis Software, LLC. August 1 - 5, 2005.
An Introduction to Object/Relational Persistence and Hibernate Yi Li
Oct * Brad Tutterow. VS 2008.NET 3.5LINQ Entity Framework  The ADO.NET Entity Framework is part of Microsoft’s next generation of.NET technologies.
JPA / HIBERNATE CSCI 6370 Nilayan Bhattacharya Sanket Sable.
Object Oriented Database By Ashish Kaul References from Professor Lee’s presentations and the Web.
Fall CIS 764 Database Systems Engineering L18.2 : Object Relational Mapping … ….Object persistence.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
1 Nov 29, 2005 Object Relational Mapping Frameworks Wiene Höweler.
Hibernate Basics. Basics What is persistence? Persistence in Object Oriented Applications? Paradigm Mismatch.  The Problem of Granularity.  The Problem.
Persistence – Iteration 4 Vancouver Bootcamp Aaron Zeckoski
Basics of JDBC Session 14.
Understand Relational Database Management Systems Software Development Fundamentals LESSON 6.1.
Mapping Objects ↔Relational DB. The Problem with Databases Databases store data in rows in tables, which are not like objects. We can simulate object.
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 5th Edition Copyright © 2015 John Wiley & Sons, Inc. All rights.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
Introduction – ORM, Helloworld Application
Introduction to ORM Hibernate Hibernate vs JDBC. May 12, 2011 INTRODUCTION TO ORM ORM is a programming technique for converting data between relational.
CS422 Principles of Database Systems Object-Relational Mapping (ORM) Chengyu Sun California State University, Los Angeles.
CS520 Web Programming Object-Relational Mapping with Hibernate and JPA Chengyu Sun California State University, Los Angeles.
CS520 Web Programming Object-Relational Mapping with Hibernate and JPA (I) Chengyu Sun California State University, Los Angeles.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
DBS201: Data Modeling. Agenda Data Modeling Types of Models Entity Relationship Model.
Hibernate Java Persistence API. What is Persistence Persistence: The continued or prolonged existence of something. Most Applications Achieve Persistence.
Rationale Databases are an integral part of an organization. Aspiring Database Developers should be able to efficiently design and implement databases.
New Technology: Why, What ,How
Chengyu Sun California State University, Los Angeles
Object-Oriented Database Management System (ODBMS)
Object-Oriented Databases
Developing and testing enterprise Java applications
Object Relational Mapping Tools
Presentation transcript:

ORM Object-Relational Mapping 1

Object Persistence Persistence is the ability of an object to survive the lifecycle of the process, in which it resides.  it is a desired feature in most nontrivial applications.  Persistence implies that data lives longer than objects.  When the program is stopped/restarted, the data from last execution is readily available. 2

Persistence Options Storing information in simple data files:  Insufficient for all but the most trivial cases (e.g., configuration data). Using object Serialization:  Supported in Java “out of the box”.  Perfect match for Java objects.  No support for non-Java environments.  Monolithic (save/store all objects every time).  Completely unusable for real-world cases. 3

Persistence Options (cont.) Using an Object-Oriented Database (OODBMS).  Maps nicely to object-oriented programs.  Not very popular.  Performance problems.  No industry standard. 4

Using a Relational Database The most common solution: a relational database. –Information is stored in tables. –Access via SQL. –Based on industry standards. –Widely accepted. –Unrivaled performance. But… How? 5

Using a Relational Database (cont.) The basic idea: –Map every persistent class to a database table e.g., Client ↔ CLIENT –Map every class field to a table field. e.g., String Name ↔ NAME (VARCHAR) –Every class instance represents a database row. –Access the database using SQL. In the case of Java, use JDBC or libraries that rely on it. 6

The Paradigm Mismatch However, there are many inherent problems to mapping object-oriented data to databases.  Granularity.  Subtypes and polymorphism.  Identity.  Associations.  Collections.  … and other problems. Let’s review a few of these problems in detail. 7

The Granularity Problem Consider the following (very typical) database table: 8

The Granularity Problem (cont.) Does the following class match? 9 class Client { String name; String mailAddressStreet; String mailAddressCity; String mailAddressState; String mailAddressZip; String billingAddressStreet; String billingAddressCity; String billingAddressState; String billingAddressZip;... methods } class Client { String name; String mailAddressStreet; String mailAddressCity; String mailAddressState; String mailAddressZip; String billingAddressStreet; String billingAddressCity; String billingAddressState; String billingAddressZip;... methods }

The Granularity Problem (cont.) What we want is the following two classes: OOP and databases work on different levels of granularity. 10 class Client { String name; Address mailAddress; Address billingAddress;... methods } class Address { String street; String city; String state; String zip; } class Client { String name; Address mailAddress; Address billingAddress;... methods } class Address { String street; String city; String state; String zip; }

Subtyping and Polymorphism Problem Consider the following class diagram: 11

Subtyping and Polymorphism Problem (cont.) How do we store BillingDetails in the database? How do we represent the relationship between Client and BillingDetails?  A foreign key can only point to one other table – CreditCard or BankAccount. 12

Identity Problem A single database row is always unique.  Assuming a primary key is used. But in OOP, multiple objects in memory can represent the same notion.  Two objects that map to the same database row. Database identity is different from object identity (“==”) and object equality (“equals()”). 13

Coping with the Paradigm Mismatch The paradigm mismatch greatly complicates OOP/RDBMS interoperability. Up to 30% of enterprise Java application code deals with persistence.  Tedious SQL/JDBC.  Bridging information representation.  Caused more than one project to sink. 14

Coping with the Paradigm Mismatch (cont.) The most accepted solution today: using middleware.  A library that bridges OOP to RDBMS.  “Object/Relational Mapping” (ORM). Java middleware solutions for persistence:  J2EE Entity EJBs.  Hibernate.  JDO (Java Data Objects). 15

Characteristics of a good ORM Solution Transparent (non-intrusive). Efficient (enables lazy-loading, selective updates, caching, etc.). Powerful (advanced querying capabilities, a lot of configuration options). Flexible (can fit into various environments such as Servlet Containers, EJB Containers, Plain Java Apps, etc.). Easy to use (mild learning curve, good testability, etc.). Supports OO idioms and concepts (inheritance, polymorphism, etc.). Standard. 16

ORM Options EJB 3 Hibernate JDO TopLink CocoBase Castor … 17