Friday, May 11, 2007

Overriding JPA mappings with Hibernate specific ones - can it be done?

Before JPA, I have always preferred Hibernate for O/R mapping, but for a project we are starting up right now, we are planning to use the standard JPA annotations. Why? Because they are a standard, and they look pretty much like what Hibernate can give us.

But then I read this post from JavaOne about what might be coming in JPA 2.0, and it gave me a feeling of quite some bit of functionality present in Hibernate but missing in JPA 1.0. A short list of what might be coming in JPA 2.0 and hence missing from the current JPA:
  • @Embeddable to map columns of a table to a class inside another class without having to map the embedded class to a table by itself
  • Ordered lists in the database
  • Specifying access types (field or property) on a pr. entity class level instead of on all entity classes
  • Uni-directional mapping on 1-N relations
There are others mentioned in the post, but these stand out to me as things that (a) I have used myself and found to be usefull, and (b) something that hibernate already has.

So, here is the question: "Is it possible to use JPA standard annotations for mapping the entities and then falling back on Hibernate specific mapping annotations when I need a specific feature that JPA does not have?". Of course, for this to work, I must be using hibernate as the JPA provider implementation.


Emmanuel Bernard said...

Hibernate Annotations have been built on top of the JPA annotations, not as a replacement.
So for most of you mapping you will use javax.persistence annotations.
And when you need a specific Hibernate feature, you will just have to complement your mapping with an org.hibernate.annotations

Per Olesen said...

Great, thanks! That is what I like to hear :-)