Friday, November 27, 2009

JPA vs Hibernate

What is difference between JPA and Hibernate as they both cater for DB persistence work in Java? Well again this is the "fight" between official and de facto standard. Long before those so-called industry experts wake up to note down a standard addressing a well-known enterprise application development issue, several groups of smart doers already raised up to invent their own "proprietary" solution to the problem. The issue is known as ORM while the groups of smart doers included Hiberate creators, Oracle's TopLink as well as the team of bringing live iBatis. The standard is JPA.

The primary reason to embrace JPA is driven by the thirst of having a standard in Object-Relational mapping - paint the door once, changing the lock often doesn't hurt (one interface with many implementation alternatives. Ideally one can be replaced by another if one doesn't suit the course anymore). However, the reality that Hiberate 3 implements JPA enables early Hibernate adopters to stay on their course while having a standard architecture in front of their governance board. In case of Red Hat deciding to discontinue open sourcing Hibernate, JPA users can switch to another implementation like OpenJPA.

On practical side of story, I would rather recommend to use Hibernate for a JPA implementation. For things that JPA can't resolve easily, use Hibernate "proprietary" features (e.g. hibernate-specific annotations). One's chance to replace a backend implementation is as uncommon as a major Open Source project getting killed. Here I said major. If you really sense the uncertainty of Hibernate and thus want to fully stick to JPA, still use Hibernate, just keep no hibernate-specific stuff.

No comments: