JPA 2.1 with EclipseLink
Ahmed Bhaila
Dealer Profiles
JPA
- Java API for Database Persistence and Reads
- Implementation Versions: 1.0, 2.0, 2.1
- Implementations




Which Implementation to choose?
-
Supports implementation JPA 2.1
-
Support for Coherence Caching
-
Good community support
EclipseLink

Reference Implementation of JPA 2.0/2.1
Based off Oracle TopLink
Plays nice with Coherence
Performs better*
Fewer Bugs
JPA Benchmark
source: http://www.jpab.org/All/All/All.html
ORM Mapping - Today
Using JPA Collections
1. Using a Set
@ElementCollection(fetch=FetchType.LAZY)
@CollectionTable(joinColumns=@JoinColumn(name="CNSMR_DLR_REV_ID"), name="CNSMR_VISIT_REAS")
@Column(name="CNSMR_VISIT_REAS_TYP_CD",insertable=false,updatable=false)
protected Set reasonsForVisit;
Result Set:
reasonsForVisit: ["SHOPNEW", "SHOPUSED", "SHOPSVC"]
More ORM Mapping
Using JPA Collections
2. Using Maps
@ElementCollection(fetch=FetchType.LAZY) @CollectionTable(joinColumns=@JoinColumn(name="CNSMR_DLR_REV_ID"), name="CNSMR_DLR_REVIEW_CTGY") @Column(name="DLR_REV_CTGY_RATE_NBR",insertable=false,updatable=false) @MapKeyColumn(name="DLR_REV_CTGY_TYP_CD") protected Map
ratings; ResultSet:
{category=OverallFacilities, value=4.0}
{category=CustomerService, value=4.0}
{category=QualityOfRepair, value=4.0}
{category=BuyingProcess, value=4.0}
Extended ON Clause
Find All Reviews with approved responses
select distinct R from Review R LEFT JOIN R.responses rr ON rr.status = 'APP' where R.dealerPartyId = :dealerPartyId
Where Exists
Find All Reviews where one of the reasons for visiting is coming in for Service and Repair
select CR from ConsumerReviews CR JOIN CR.reviews R JOIN R.ratings RA JOIN R.reasonsForVisit VR " +
"LEFT JOIN R.responses rr ON rr.status = 'APP' where exists(select v from VisitReason v where v.visitReasonCode = 'SVCREPAIR' and v.reviewId = R.reviewId) " +
"and CR.dealerPartyId = :dealerPartyId and R.status='APP' " +
"ORDER BY R.overallRating DESC, R.submittedDate DESC
JPA QueryHints
Can be used to customize or optimize queries
-
QueryHints.FETCH
- QueryHints.LEFT_FETCH
query="select CR from ConsumerReviews CR JOIN CR.reviews R JOIN R.ratings RA LEFT JOIN R.responses rr ON rr.status = 'APP' where CR.dealerPartyId = :dealerPartyId and R.status='APP' ORDER BY R.submittedDate DESC",
hints={
@QueryHint(name=QueryHints.FETCH, value="CR.reviews"),
@QueryHint(name=QueryHints.LEFT_FETCH, value="CR.ratings"),
@QueryHint(name=QueryHints.LEFT_FETCH, value="CR.reviews.reasonsForVisit"),
@QueryHint(name=QueryHints.LEFT_FETCH, value="CR.reviews.ratings"),
@QueryHint(name=QueryHints.LEFT_FETCH, value="CR.reviews.responses"),
}
Other QueryHints
- QueryHints.BATCH_SIZE - The number of keys in the "IN" clause
- QueryHints.QUERY_RESULTS_CACHE - To Cache or not to Cache
Questions?

JPA 2.1 with EclipseLink
By Ahmed Bhaila
JPA 2.1 with EclipseLink
- 180