Friday, July 17, 2009

JPA 2.0 New Features

JPA 2.0 is releasing 2009 fall. (JSR 317)


--> Fil in ORM mapping gaps
--> Make object modeling more flexible
--> offer simple cache control abstraction
--> allow advanced locking settings
--> JPQL enhancements

More standardized properties
--> some properties are used by each and every driver

Persistent unit properties like javax.persistence.jdbc.driver, javax.persistence.jdbc.url

JPA 2.0 supports join table as well as f key relationships.
Collections of embeddables or basic values.

This is made possible using elementcollection annotation

order is maintained even if you move things around by using an index.

More Map flexibility
Map Keys and values can be : Basic objects,embeddables, entities

Enahcned embedded support
Embeddables can be nested and can have relationships

Access Type options
--> mix access modes in a hierarchy (field or properties)
@Access annotation

Derived Identities
JPA 1.0 relationship field cannot be part of the id

JPA 2.0 @Id + @OneToOne

Second Level Cache
API for operating on entity cache which is accessible from EntityManagerFactory
Supports only ver basic cache operations , which can be extended by vendors

@Cacheable annotation on entity (default is true)

There is also a property by the name shared-cache-mode to denote per PersistenceUnit whether to cache.
--no entities
--only cacheable entities
-- all entities

Properties cacheRetreiveMode and cacheStoreMode per EM method call whether to
read from cache

1.0 allows only for optimistic locking
2.0 provides for optimistinc locking by default
pessimistic locking can be used per entity or query

Lock mode values introducted
Optimistic (=READ)

API Additions
Lockmode parameter added to find,refresh
Properties parameter added tofind,refresh,lock
Other useful additions
void detach(Object entity)
Query API addition
Enhanced JP QL
Timestamp literals
Non-polymorphic queries
IN expression may include collection parameter --> IN (:param)
Ordered List indexing
CASE statement

Criteria API
Similar to eclipselink expressions,hibernate criteria
Criteria API - Canonical Metamodel
--> For every managed class , there is a metamodel class

Load State Detection
JPA can integrate with Bean validation (JSR 303) : Hibernate Validator is an implentation

JPA 2.0 shpped as part of Java EE6 release

No comments: