Sunday, April 17, 2011

org.hibernate.annoatations vs. javax.persistence

Is it a bad idea to use the annotations from the

javax.persistence package

instead of using the

org.hibernate.annotations annotations

I know that using javax.peristence does introduce yet another dependency. But if I ignore that, what are the pros/cons?

From stackoverflow
  • Quite the oppsite.

    Hibernate is an implementation of the Java Persistence API, and where possible, you should use the standard annotations (in javax.persistence). This way, you could theoretically run your code on other JPA implementations.

    Only when you need Hibernate-specific functionality should you use the Hibernate annotations.

    The extra dependency is only on the JPA interface/annotation jar files and very light.

    Schildmeijer : so its possible to mix annotations from these packages (javax.persistence & org.hibernate.annotations) withing an @Entity
  • I used javax.persistence annotation, and when I replaced Tomcat 6.0 with my Glass Fish, then Tomcat 6.0 included another javax.persistence package that messed everything. I don't think it's a good idea to use javax.persistence annotation. God know what the hell happened with Tomcat and javax.persistence!

0 comments:

Post a Comment