JPA实体和Hibernate实体的区别 [英] Difference between JPA Entity and Hibernate Entity

查看:121
本文介绍了JPA实体和Hibernate实体的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用@Entity注解一个类并尝试解析依赖关系时,我可以选择两个不同包之间的包,javax.persistence.Entity和org.hibernate.annotations.Entity

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.hibernate.annotations.Entity

javax包是JPA的实体注释,但是为什么会有一个hibernate实体注释,并且它与JPA注释有区别?它只是一个允许定义更多属性的扩展?

The javax package is JPA's entity-annotation, but why is there a hibernate entity-annotation and difference does it have with JPA's annotation? Is it just an extension to allow more attributes to be defined?

推荐答案

org.hibernate.annotations。实体有一些额外的属性, javax.persistence.Entity 尚未标准化。额外的功能只有在直接使用hibernate的 AnnotationConfiguration 或hibernate是JPA提供程序时才能正常工作。

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.


来自常见问题解答
编辑:新链接具体问题

编辑:新链接答案: p>

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


我使用@ org.hibernate.annotations.Entity并获取未知实体异常

总是导入@ javax.persistence.Entity

Always import @javax.persistence.Entity

@ org.hibernate.annotations.Entity completes @j avax.persistence.Entity,但不是替代品

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

例如,有一个名为 optimisticLock ,它告诉hibernate在更新时是使用标准版本列还是比较所有列。这种行为不在JPA规范中,所以为了配置它,你必须使用在他们自己的注释中找到的特定于hibernate的扩展。

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.

像这样:

@Entity
@org.hibernate.annotations.Entity(optimisticLock=OptimisticLockType.ALL)
public class MyEntity implements Serializable {
...
}

这篇关于JPA实体和Hibernate实体的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆