JPA Myth - Busted!
By Prashant Dighe on Aug 18, 2009
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.
"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.
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.
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.
- overriding accesors in entity need tranisent declaration
- getter interpreted as property
- presence of getX as well as isX thorws MappingException
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.