休眠注解 [英] Hibernate annotation

查看:43
本文介绍了休眠注解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在基于 Hibernate 的应用程序中,我们应该使用 @org.hibernate.annotations.Entity 而不是 @javax.persistence.Entity 吗?

Should we use @org.hibernate.annotations.Entity instead of @javax.persistence.Entity in Hibernate based applications?

或者没有这样的规定?

推荐答案

@org.hibernate.annotations.Entity 补充 @javax.persistence.Entity.

有关详细信息,请参阅此紧密相关的问题:JPA 实体和休眠实体之间的区别.如上所述,您不应该在没有 @javax.persistence.Entity 的情况下使用 @org.hibernate.annotations.Entity.Hibernate 注释将允许您向标准 JPA 中已定义的功能添加一些额外的特定于 Hibernate 的功能.

See this tightly related question for details: Difference between JPA Entity and Hibernate Entity. As stated there, you shouldn't be using @org.hibernate.annotations.Entity without @javax.persistence.Entity. The Hibernate annotation will let you add some extra hibernate-specific features to the ones already defined in the standard JPA one.

JPA 注释具有将代码与您使用的特定引擎解耦的优势,并且 Hibernate 注释为 JPA 标准注释添加了一些额外的特性/属性,例如 optimisticLock.如果您需要使用这些属性,请仅使用 @org.hibernate.annotations.Entity.

The JPA annotation has the advantange of decoupling your code from the specific engine you're using, and the Hibernate annotation adds some extra features/attributes to the JPA standard annotation, like optimisticLock. Only use @org.hibernate.annotations.Entity if you need to use those attributes.

这篇关于休眠注解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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