J P i t API Java Persistence API

10 downloads 36695 Views 710KB Size Report
Customized Java EE Training: http://courses.coreservlets.com/. Servlets, JSP, Struts ... Taught by the experts that brought you this tutorial. Available at public ...
© 2009 coreservlets.com

J Java P Persistence i t API Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/Course-Materials/hibernate.html Customized Java EE Training: http://courses.coreservlets.com/ Servlets, JSP, Struts, JSF/MyFaces/Facelets, Ajax, GWT, Spring, Hibernate/JPA, Java 5 & 6. Developed and taught by well-known author and developer. At public venues or onsite at your location.

© 2009 coreservlets.com

For live Spring & Hibernate training, see courses att http://courses.coreservlets.com/. htt // l t / Taught by the experts that brought you this tutorial. Available at public venues, venues or customized versions can be held on-site at your organization. • Courses C d developed l d and d ttaught ht b by M Marty t H Hallll – Java 5, Java 6, intermediate/beginning servlets/JSP, advanced servlets/JSP, Struts, JSF, Ajax, GWT, custom mix of topics

• Courses developed and taught by EE coreservlets.com experts (edited by Marty) Customized Java Training: http://courses.coreservlets.com/ – Spring, Hibernate/JPA, EJB3, Ruby/Rails

Servlets, JSP, Struts, JSF/MyFaces/Facelets, Ajax, GWT, Spring, Hibernate/JPA, Java 5 & 6. Contact [email protected] for details Developed and taught by well-known author and developer. At public venues or onsite at your location.

Topics p in This Section • Become acquainted q with the Java Persistence API (JPA) • Compare and contrast Hibernate and JPA • Learn how to setup and use Hibernate as a JPA provider

5

© 2009 coreservlets.com

Java Persistence API (JPA) Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/Course-Materials/hibernate.html Customized Java EE Training: http://courses.coreservlets.com/ Servlets, JSP, Struts, JSF/MyFaces/Facelets, Ajax, GWT, Spring, Hibernate/JPA, Java 5 & 6. Developed and taught by well-known author and developer. At public venues or onsite at your location.

Java Persistence API • Developed as part of Java S Specification ifi ti R Requestt (JSR) 220 – Original goal to simplify EJB CMP entity beans

• Si Simplifies lifi th the d development l t off J Java EE and Java SE applications using data persistence i t • Brings the Java community behind a single, i l standard t d d persistence i t API • Draws upon the best ideas from existing persistence technologies – Hibernate, TopLink, and JDO

Java Persistence API • Usable both within Java SE environments i t as well ll as Java J EE – POJO based – Works k with i h XML descriptors d i andd annotations

•E Existing i ti EJB CMP applications li ti continue to work unchanged • May M become b partt off Java J SE – Likely that this issue will be considered by th Java the J SE expertt group in i a future f t Java J SE release

Main JPA Components p • Entity Classes • Entity Manager – Persistence Context

• EntityManagerFactory y • EntityTransaction • Persistence Unit – persistence.xml

• Java Persistence Query Language (JPAQL) – Query

Hibernate vs. JPA Components p JPA

Hibernate

Entity Classes

Persistent Classes

E tit M EntityManagerFactory F t

S SessionFactory i F t

EntityManager

Session

Persistence

Configuration

E tit T EntityTransaction ti

T Transaction ti

Query

Query

Persistence Unit

Hibernate Config

Persistence Unit • Defines all entity classes that are managed by JPA p • Identified in the persistence.xml configuration file • Entity y classes and configuration g files are packaged together – The JAR or directory that contains the persistence.xml i l is i called ll d the h root off the h persistence unit – Needs to be inside a META-INF directory • Whether or not inside a jar

p persistence.xml

org.hibernate.ejb.HibernatePersistence hib t jb Hib t P i t orm.xml c courses.hibernate.vo.Account s s hib t Acc t courses.hibernate.vo.AccountOwner courses.hibernate.vo.AccountTransaction courses hibernate vo EBill courses.hibernate.vo.EBill courses.hibernate.vo.EBiller ...

p persistence.xml ... properties / ti

persistence.xml: Pass-Through p g • Can satisfy the persistence.xml requirement with ith a pass th through h to t an existing i ti Hibernate Hib t configuration file