Hibernate and JPA
In the beginning there was Hibernate, an open source object-relational mapping tool (ORM) which used a proprietary API
and XML for the mapping metadata.
Then, because of Hibernate's popularity, a standard Java specification for ORM
called the Java Persistence API (JPA) was introduced as part of EJB 3.0.
This specification favoured annotations over XML for the mapping metadata
(although XML can still be used to override annotations at runtime) and introduced
a new standardized API.
JPA was implemented by Hibernate as a thin wrapper around its existing core and
the native Hibernate API was extended to allow JPA annotations to be used for the mapping
metadata. Also, because JPA delivers only a subset of the functionality provided by Hibernate,
additional Hibernate specific annotations were added to compensate for the difference.
So, when using Hibernate, we are faced with these options.
- Use traditional Hibernate with the native API and XML metadata.
- Use the native API with JPA annotations, with or without the Hibernate extensions.
- Use JPA with standard annotations with the option to override the metadata with XML.
As a guideline, if cross-vendor standardization is a priority then use JPA.
If additional features and more frequent product releases are more
important than the ability to easily switch vendors, consider using native Hibernate.
This tutorial focuses on the second option.