Difference between JPA Entity and Hibernate Entity

后端 未结 3 1377
说谎
说谎 2020-12-02 14:37

When I annotate a class with @Entity and try to resolve the dependencies, I get to choose the package between two different packages, javax.persistence.Entity and org.hibern

相关标签:
3条回答
  • 2020-12-02 15:08

    org.hibernate.annotations.Entity has some extra attributes that javax.persistence.Entity has not standarized. The extra features will only work if using hibernate's AnnotationConfiguration directly or if hibernate is the JPA provider.

    from the FAQ: edit: new link the specific question: edit: new link the answer:

    I use @org.hibernate.annotations.Entity and get an Unknown entity exception

    Always import @javax.persistence.Entity

    @org.hibernate.annotations.Entity completes @javax.persistence.Entity but is not a replacement

    For instance, there is an attribute called optimisticLock, which tells hibernate whether to use the standard version column or to compare all columns when updating. This behavior is not in the JPA spec, so in order to configure it, you must use hibernate specific extension found in their own annotation.

    Like this:

    @Entity
    @org.hibernate.annotations.Entity(optimisticLock=OptimisticLockType.ALL)
    public class MyEntity implements Serializable {
    ...
    }
    
    0 讨论(0)
  • 2020-12-02 15:09

    I'm not sure about the differences but I am sure that if you have the Hibernate jars in your classpath you are using Hibernate JPA. Hibernate provides an implementation of JPA. Even though you are using the javax.persistence package you are using Hibernate JPA.

    The difference could be only in the naming. They might provide the same classes both in the Hibernate package space and the javax package space.

    0 讨论(0)
  • 2020-12-02 15:10

    @org.hibernate.annotations used in your project, if suppose you want to use JDBC template or ibatis we need to change the code. if we use javax.persistence there is no need to change the code. This is the main difference between org.hibernate.annotations and javax persistence

    0 讨论(0)
提交回复
热议问题