Persistence

11
Ennovation – Behind the Products Anish Alex, CTO

description

Java Persistence

Transcript of Persistence

Page 1: Persistence

Ennovation – Behind the Products

Anish Alex, CTO

Page 2: Persistence

• Closest native language support– Serialization

• Lifecycle– Begins and Ends with JVM

• Identity– Equals / Hashcode / Memory Location

• Data Types– Int/long/string..

• RDBMS– Long term persistence / Primary Key – SQL– VARCHAR / NUMBER

2 Evolvus Solutions. Proprietary and Confidential, do not copy, duplicate or distribute.

Java Persistence Problem

Page 3: Persistence

• Object Relational Mappers – ORM’s– Map Java objects to Relational database

table records e.g.– Top Link / Hibernate

• Java Data Objects (JDO)– Apache jdo

• JDBC• Java Persistence API (JPA)

– Hibernate– Top Link– Open JPA

• EJB• Custom

3 Evolvus Solutions. Proprietary and Confidential, do not copy, duplicate or distribute.

Java Persistence Technologies

Page 4: Persistence

Java Persistence Technologies

Evolvus Solutions. Proprietary and Confidential, do not copy, duplicate or distribute.4

Page 5: Persistence

HibernateRelational Persistence for Java

Page 6: Persistence

• XML file to map POJO to Tables• Configuration• Classes to bootstrap the framework• JPA Implementation

6 Evolvus Solutions. Proprietary and Confidential, do not copy, duplicate or distribute.

Hibernate - Relational Persistence for Java

Page 7: Persistence

Sample CodeORM

Page 8: Persistence

• Generators– native– increment– sequence– assigned– hilo / identify / uuid.hex / uuid.string / foreign

• Version– Prevents invalid overwrites

• Property– String – specify length– BigDecimal – specify precision/scale– Date / Timestamp / Long - nothing to specify

8 Evolvus Solutions. Proprietary and Confidential, do not copy, duplicate or distribute.

Hibernate ORM

Page 9: Persistence

• References– http://www.mkyong.com/tutorials/hibernate-

tutorials/– http://docs.jboss.org/hibernate/orm/3.3/

reference/en/html/index.htmlPrevents invalid overwrites

– Sample code - http://codeserver/demo-repository/svndemo/anisht/trunk/training/hibernate

9 Evolvus Solutions. Proprietary and Confidential, do not copy, duplicate or distribute.

Hibernate ORM

Page 10: Persistence

• To-Do– One-to-Many using foreign keys– Many-to-One– Many-to-One using foreign keys– One-to-One– Run the same examples against SQL Server

10 Evolvus Solutions. Proprietary and Confidential, do not copy, duplicate or distribute.

Hibernate ORM

Page 11: Persistence

THANK YOU !!

Questions / Contact