且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Hibernate或JPA注释

更新时间:2023-09-15 11:51:52

的JPA实现。如果您在代码中使用纯粹的JPA,那么如果出现需求,您可以***地更改为不同的实现。例如, EclipseLink / TopLink OpenJPA 是针对不同客户可能需要的实现。一个完整的实现列表是这里



如果您不得不使用hibernate提供的任何不属于JPA规范的奇特功能,则应该在您的代码库中使用hibernate特定的API。 hibernate论坛此处的相关讨论。


I am using Hibernate in our projects and annotation based configuration for Hibernate Domain Pojo Objects. For Annotations based configuration we have two options

  1. JPA based annotations using javax.persistence.*
  2. Use Hibernate Native Annotations org.hibernate.annotations.*

Currently we use JPA based annotation configuration for our POJO files and Hibernate native API like SessionFactory, Session, etc to open session and perform DB operations.

Need your help in below things,

  1. Is there any problem mixing both JPA annotations and use Hibernate native API?
  2. This link explains one such issue (cascade-jpa-hibernate-annotation-common-mistake)
  3. Please provide your expertise, which type of annotations to use
    1. JPA
    2. Hibernate native
    3. mix both of them?

Hibernate provides one of the JPA implementations. If you use purely JPA in your code, you are free to change to a different implementation if a requirement arises. For example, EclipseLink/TopLink and OpenJPA are implementations which may be required for a different customer. A comprehensive list of implementations is here.

If you are compelled to use any exotic features provided by hibernate which are not in JPA specification, you should go for hibernate specific APIs in your code base. A related discussion from hibernate forum here.