Introduction to JPA Java Persistence API Introduction to JPA
ORM Object-Relational Mapping Problem Object oriented programming languages Relational DBMS Several ORM frameworks has tried to ”fix” the problem Example: Hibernate JPA standardizes O/R mapping Introduction to JPA
Impedance mismatch EJB 3 In Action, page 252 OO model Relational model Class, object Table, row Attributes Columns Identity Primary key Methods Stored procedures Inheritance Not supported Polymorphism Introduction to JPA
Java EE 5 JPA is part of Java EE 5 JPA works between the Business Tier and the EIS tier (Enterprise Information System) Figure from ”Java EE 5 Tutorial” http://java.sun.com/javaee/5/docs/tutorial/doc/bnaay.html Introduction to JPA
Java EE 5 Some Java EE 5 containers GlassFish from Sun Application Server from Oracle JBoss WebSphere from IBM WebLogic from BEA BEA was recently acquired by Oracle Apache Tomcat Not a full Java EE container, only a web container Introduction to JPA
Java Persistence API JPA is an API Some persistence providers Implemented by a persistence provider Like JDBC is an API implemented by Some persistence providers Hibernate from JBoss TopLink from Oracle Kodo from BEA recently acquired by Oracle Introduction to JPA
The class EntityManager EntityManager is the most important class of JPA Full name javax.persistence.EntityManager Some methods of EntityManager T find(primaryKey) Query createQuery(String jpql) Creates a JPQL query Query createNativeQuery(String sql) Creates a SQL query Some methods of Query List getResultList() Executes a Query and returns a list of objects Introduction to JPA
Java Persistence Query Language (JPQL) Very much like ordinary SQL But not specific to any DBMS JPA converts JPQL to ordinary SQL for the actual DBMS Introduction to JPA
EJB 3 EJB 3 Enterprise Java Beans Important part of Java EE 5 Much simpler than EJB 2 POJO + annotations Plain Old Java Objects EJB classes can Create database tables or Be created from database tables Introduction to JPA