java Hibernate - 注释和公共注释之间的区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11171154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hibernate - difference between annotations and commons-annotations?
提问by Sam Levin
To keep it short and sweet:
为了保持简短和甜蜜:
There is hibernate-commons-annotations 4.1.0-Final and hibernate-annotations 3.5.6-Final.
有 hibernate-commons-annotations 4.1.0-Final 和 hibernate-annotations 3.5.6-Final。
I'm a nub, what's the difference between them, and do I need them both?
我是个小人,它们之间有什么区别,我需要它们吗?
Trying to "avoid" JPA and by that I mean using the JPA 2.0 standards embedded within Hibernate.
试图“避免”JPA,我的意思是使用嵌入在 Hibernate 中的 JPA 2.0 标准。
Thanks!
谢谢!
回答by Ravi Kadaboina
Previously, hibernate-annotations was released and versioned from hibernate core. But from version 3.5 and up it is included with hibernate core. And for some reason it was still released from 3.5.0 to 3.5.6 but you do not need it anymore.
以前,hibernate-annotations 是从 hibernate 核心发布和版本化的。但是从 3.5 及更高版本开始,它包含在休眠核心中。出于某种原因,它仍然从 3.5.0 发布到 3.5.6,但您不再需要它了。
And coming to hibernate-commons-annotations, it is a utility project used by annotations based hibernate sub-projects. It is used by other hibernate projects like hibernate-search and thus is maintained as a separate project and it is a compile time dependency for hibernate-core v3.6.0 and up.
来到 hibernate-commons-annotations,它是一个由基于注释的 hibernate 子项目使用的实用程序项目。它被其他 hibernate 项目如 hibernate-search 使用,因此作为一个单独的项目进行维护,它是 hibernate-core v3.6.0 及更高版本的编译时依赖项。
回答by Mikko Maunu
Hibernate Commons Annotations is "Utility project for annotation handling", as said for example here. It does not contain such API that normal user of Hibernate should use.
Hibernate Commons Annotations 是“用于注释处理的实用程序项目”,例如此处所述。它不包含普通 Hibernate 用户应该使用的 API。
Hibernate annotations contained persistence mapping annotations and related code. Nowadays it is merged to Hibernate core.
Hibernate 注释包含持久性映射注释和相关代码。现在它已合并到 Hibernate 核心。
If you really want to avoid JPA (1/2) that is easily done by not using classes from javax.persistence
package or from its subpackages. If you want opposite, use javax.persistence
and avoid org.hibernate
packages where possible.
如果您真的想避免通过不使用javax.persistence
包或其子包中的类来轻松完成的 JPA (1/2) 。如果您想要相反,请尽可能使用javax.persistence
并避免使用org.hibernate
包。
Good guide to get started with Hibernate can be found from http://docs.jboss.org/hibernate/orm/4.1/quickstart/en-US/html_single/. It also tells which libraries are needed always and which ones are optional.
可以从http://docs.jboss.org/hibernate/orm/4.1/quickstart/en-US/html_single/找到开始使用 Hibernate 的好指南。它还说明哪些库总是需要的,哪些是可选的。
Reference documentationcontains plenty of advices about using JPA instead of deprecated legacy Hibernate annotations.
参考文档包含大量关于使用 JPA 而非弃用的遗留 Hibernate 注释的建议。