Novedades JavaEE 6: JPA 2.0
JavaEE 6 ha introducido una revisión de la capa de persistencia (Java Persistence API o JPA) que introduce algunas novedades. Quizás no suficientes para justificar el cambio de numeración mayor, pero quizás haya venido dado por el Criteria API, que ha sido un añadido bastante pretencioso que busca un código de mayor calidad quizás no para los desarrolladores sino para generadores automáticos de código.
Map Key Columns
Permite que una relación que habitualmente se representaría como una lista pueda representarse como un mapa incluyendo como clave algunos valores de la tabla de destino (entre otros).
Undirectional OneToMany
JPA 1.0 does not support a unidirectional OneToMany relationship without a JoinTable. JPA 2.0 will have support for a unidirectional OneToMany. In JPA 2.0 a @JoinColumn can be used on a OneToMany to define the foreign key.
Order Column
JPA 2.0 adds support for an OrderColumn. An OrderColumn can be used to define an order List on any collection mapping.
EntityManager and Query API
Both the EntityManager and Query APIs have been enhanced to support things like retrieving the first result (JPA 1.0 allowed the retrieval of a unique result), specifying the maximum size of query results, getting access to the underlying vendor-specific entity manager/query objects and pessimistic locking (JPA 1.0 only supported optimistic locking).
Criteria API
JPA 2.0 defines a query criteria API in an attempt to simplify dynamic query creation. With JPQL dynamic queries would require performing string concatenations to build queries dynamically from web forms or dynamic content. JPQL is also not checked until runtime, making typos more common. The criteria API using a set of Java interfaces to allow queries to be dynamically constructed, and reduces runtime typos with compile time checking.
JPQL enhancements
JPQL has been enhanced with SQL-like CASE, NULLIF, COALESCE and like capabilities.
Referencias
- http://en.wikibooks.org/wiki/Java_Persistence/What_is_new_in_JPA_2.0
- Especificación JPA 2.0
- http://www.oracle.com/technetwork/java/javaee/tech/index.html