java - 使用 Hibernate EntityManager(与 Hibernate Core 相比)有什么缺点吗?

标签 java hibernate orm jpa jpa-2.0

Hibernate EntityManager 文档 states ,即:

You may use a combination of all three together, annotations without JPA programming interfaces and lifecycle, or even pure native Hibernate Core, depending on the business and technical needs of your project. You can at all times fall back to Hibernate native APIs, or if required, even to native JDBC and SQL.

使用 JPA API (EntityManager) 的代码显然更易于移植(即使偶尔回退到 Hibernate Core)。

但是当我使用纯粹的 Hibernate Core 时会有什么优势吗?我想知道,JPA 2 模型是否真的适用于 Hibernate Core 而没有任何矛盾? IOW,回退到 Core 是否总是容易且没有问题?

我主要担心的是:

也许差异不仅在于 API,还在于底层语义?! (例如,可能会发生冲突的不同事务/版本控制/锁定语义:Core 文档中提到了悲观锁定,但 EntityManager 文档中没有提到 - 所以我仍然可以通过回退到 Core 来使用悲观锁定而不会引起问题吗?类似的事情...... .)

最佳答案

But would I have any advantages when using purely Hibernate Core?

如果 JPA 2.0 支持您的需求,我认为直接使用 Hibernate Core 没有任何优势(并且使用 JPA 2.0,差距变得更小,使得需要回退到 Core 成为异常(exception),而不是规则,这是一件非常好的事情)。

I wonder, if the JPA 2 model really fits on top of Hibernate Core without any contradictions?

自 JPA 1.0 以来,Hibernate 开发人员在创建 Hibernate3 时就“牢记 JPA”,并在 Hibernate3 中采用了 JPA 语义、默认值等。您可能想在这个 Tech Talk: Gavin King on Hibernate3 and EJB3 中听听 Gavin :

In this tech talk King discusses how Hibernate3 builds upon and extends EJB3, addressing such topics as:

  • New features of Hibernate3
  • The relationship between Hibernate3 and the EJB3 container in JBoss
  • What differentiates Hibernate3 from the EJB3 specification
  • Hibernate's custom annotations available outside EJB
  • The future of Hibernate

并且根据我的实践经验,Hibernate 与 EJB 3 并不矛盾这一事实是正确的。

IOW, is a fallback to Core always easy and without problems?

无论您是否直接使用 Core,您都正在使用它(EntityManagerSession 的包装器)。所以,是的,如果你真的需要的话,回到 Core 是很容易的(例如,对于那些仍然不在规范中的东西,比如 Query By Example)。而且,不,这不会导致任何问题(因为您实际上是在 JPA 中使用它或它的一个子集)。

相关问题

关于java - 使用 Hibernate EntityManager(与 Hibernate Core 相比)有什么缺点吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3440532/

相关文章:

Java:Oauth 2.0 如何使用 Google API RefreshTokens 来避免在我的应用程序每次启动时请求访问?

mysql - 长时间闲置后,服务器在 spring-boot-starter-data-jpa 中使用 Mysql 抛出错误 'Could not open JPA EntityManager for transaction'

hibernate - 如何删除 ColdFusion ORM 中的关联?

hibernate - 使用多个事务管理器与 hibernate-spring 集成(基于注释)

oop - 戈兰 : Is there any way to access the "child" struct in the "parent" struct's methods in Go's composition model?

javascript - Adonis JS v5 关系缺少模型属性

java - 对象属性为相同长度的表示以加快阅读速度

java - UnsatisfiedLinkError Libgdx 桌面

java - 方法程序未显示预期结果

java - Spring事务和多表回滚