Hibernate persistence
Hibernate Persistence
What is persistence persist data to database or other storage a In Oo world, persistence means persist object to external storage Relational database SQL a Using SQL in Java a Persistence object-oriented applications: ORM
What is Persistence ◼ Persist data to database or other storage. ❑ In OO world, persistence means persist object to external storage. ◼ Relational database ❑ SQL ❑ Using SQL in Java ❑ Persistence object-oriented applications: ORM
What is Hibernate? Popular Open Source(LGPL) Object/Relational Mapping(oRM) tool Transparent persistence for POJOs (Plain Old Java objects Core of JBoss Cmp 2.0 impl
What is Hibernate? ◼ Popular Open Source (LGPL) Object/Relational Mapping (ORM) tool ◼ Transparent persistence for POJOs (Plain Old Java Objects) ◼ Core of JBoss CMP 2.0 impl
Why Hibernate? Minimizes code Does not require a container Model is not tied to persistence implementation, Retains natural object model (transparent)
Why Hibernate? • Minimizes Code • Does not require a container • Model is not tied to persistence implementation, Retains natural object model (transparent)
Object/Relational Mapping Javaobject SOL Table int id; string namei string getName( id [int] primary key, int getId() void setName(string) name [varchar(50) void setId(int) Magic Happens Here (O/R Mapper-1e Hibernate)
Object/Relational Mapping JavaObject int id; String name; String getName() int getId() void setName(String) void setId(int) SQL Table id [int] primary key, name [varchar(50)] Magic Happens Here (O/R Mapper – i.e. Hibernate)
Course ob Ject Model > Gender female ma⊥e +course Course eacher tname tname string +totalStudent s > Address +postCode Normalcourse OnlineCours +classroomname tURL
Course Object Model
Persistence tasks Class mapping a Class to Table mapping a Object id to Primary Key Attribute Mapping a Primary Attribute to column a User defined data type to embedded type Inheritance Mapping Relationship Mapping a One to Many a many to one
Persistence Tasks ◼ Class mapping ❑ Class to Table mapping ❑ Object ID to Primary Key ◼ Attribute Mapping ❑ Primary Attribute to Column ❑ User defined data type to embedded type ◼ Inheritance Mapping ◼ Relationship Mapping ❑ One to Many ❑ Many to One
Persistence/ Concurrency Pattern Introduced Martin fowlery《企业应用架构模式》
Persistence /Concurrency Pattern Introduced Martin Fowler《企业应用架构模式》
Persistence What is persistence a Why Persistence is Importance History of persistence a Plan text 口RDB(OODB? D XML
Persistence ◼ What is Persistence ◼ Why Persistence is Importance ◼ History of persistence ❑ Plan text ❑ RDB(OODB?) ❑ XML
Mapping to a relational database Metadata Mapping Identity Field lazy load Query Object
Mapping to a Relational Database ◼ Metadata Mapping ◼ Identity Field ◼ Lazy Load ◼ Query Object