JPA Myth - Busted!

Conclusion first for the busy
Like MythBusters of Discovery channel - If your application uses JPA compliant persistence, then you can plugin any JPA provider - Busted!
As yet, Aug 2009, which is more than three years after JSR 220 release, and five months after proposed final draft of JSR 317, it is still not possible to switch JPA providers. And remember, we are not talking about Hello World!
Moreover, EclipseLink turns out to be the winner when it comes to a real application.

Don't believe it, read on....

Liferay is one of the most popular open source portal and is consumed by WebSpace as its portal core. Currently, Liferay uses non-JPA Hibernate. I was working on implementing JPA persistence layer for Liferay.  This is a real world application with over 100 entity classes and as many tables. The experience below is the summary of what I found during this implementation.

The Spec
"xml-mapping-metadata-complete" tag only means ignore annotations. Even if you have specified it in the mapping xml, all providers (EclipseLink/Hibernate/OpenJPA), look into the entity classes (some for accessors while some for just getters) claiming spec adherence, when access is declared to be of type "PROPERTY".
I would interpret "xml-mapping-metadata-complete" as an indication to the provider that this is it. Whatever is there in the mapping xml is what you are supposed to deal with. Look no further. But that's not the case.
This results in 80% of the mapping file to contain transients defined for accessors which are not supposed to be interpreted as persistent properties.

TopLink/EclipseLink
It works!
Although I hit a small bug, the forum quickly provided a workaround.
Other than that, it was smooth.

Neither Hibernate nor OpenJPA work unless mapped-superclass is defined when entity class is a sub-class. See this forum post  for details. Since the spec requires mapped-super class declaration, it is okay for providers to expect it but EclipseLink works with or without it. I don't mind even if it violates the spec.

Hibernate
As mentioned earlier, the mapped-superclass declaration is needed for entity classes which are subclasses.  Otherwise Hibernate throws this exception,
Caused by: org.hibernate.AnnotationException: No identifier specified for entity ...
This is fine since spec defines it this way but it was difficult to figure out from the exception.

But here are the serious stopper issues.

  1. overriding accesors in entity need tranisent declaration
  2. getter interpreted as property
  3. presence of getX as well as isX thorws MappingException
OpenJPA
OpenJPA has a serious issue that the overridden setters in entity class are never called. It only calls the setters of the mapped-superclass. This totally breaks the application.
The details are in this forum question.

I have not heard of a solution or a workaround from either Hibernate or OpenJPA forums, and hence the conclusion. If I get some help from them, I will be happy to re-visit and make this work. But as of now, only TopLink/EclipseLink works for me.
Comments:

Post a Comment:
Comments are closed for this entry.
About

Prashant Dighe

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today