2. Java Persistence Problem
• 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.
3. Java Persistence Technologies
• 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.
6. Hibernate - Relational Persistence for Java
• 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.
8. Hibernate ORM
• 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.
9. Hibernate ORM
• References
– http://www.mkyong.com/tutorials/hibernate-
tutorials/
– http://docs.jboss.org/hibernate/orm/3.3/refe
rence/en/html/index.htmlPrevents invalid
overwrites
– Sample code - http://codeserver/demo-
repository/svndemo/anisht/trunk/training/hib
ernate
9 Evolvus Solutions. Proprietary and Confidential, do not copy, duplicate or distribute.
10. Hibernate ORM
• 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.
1. Behind the products 2. IT management peace of mind Freedom of choice Any relational database - oracle/mysql/mssql/db2 Any application server - JBoss, Websphere, Weblogic - even Tomcat! Any os - Windows, Linux, *nix Any hardware - well, almost :-) - no mainframes Good corporate citizen Integrates with monitoring systems - Integrates with various SSO systems - Siteminder, CAS, AD, Custom Solutions Easy test instance creation Built in purge/backup solution Test automation Minimal IT involvement 3. High performance/High Scalability 4. Industrial strength Cluster enabled - Application and database failover 5. Open Source No Vendor Lock-in Community Contribution 6. Device inclusive Tablets / Smart Phones / Desktop
Closest to persistence in Java means Serialization Objects created and destroyed based on scope, GC frequency – eventually JVM Objects identified by Memory location by default, or by overriding the equals/hashcode methods No Mapping to Relational databases – Primary Key / Foreign Key / Data type constraints
Several competition mechanisms to solve the problem of Java Object Persistence ORM -> Object to Relational Database JDO -> Object to File/XML/Relational database – Multiple targets, JDOQL, Annotations, XML Custom like iBatis -> Using SQL/Stored Procedures JPA -> Object to Relational Database, JQL, Annotations JDBC -> Using SQL’s EJB’s -> Entity Beans
Configure which database you want to connect to / the dialect, driver etc.