Hibernate 5中的org.hibernate.transaction.JDBCTransactionFactory类在哪里? [英] Where did the class org.hibernate.transaction.JDBCTransactionFactory go in Hibernate 5?

查看:858
本文介绍了Hibernate 5中的org.hibernate.transaction.JDBCTransactionFactory类在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在从Hibernate 3.x升级到5.x的项目。现在hibernate配置xml中的一个属性如下:

 < property name =hibernate.transaction.factory_class > org.hibernate.transaction.JDBCTransactionFactory< /性> 

在Hibernate 5中,这个特定的类以及包 org.hibernate。交易似乎不存在。这个类在3.x版本中可用,但是( https://docs.jboss.org/hibernate/envers/3.6/javadocs/org/hibernate/transaction/JDBCTransactionFactory.html )。
每个Hibernate 5 API文档都没有这样的类( https:// docs .jboss.org / hibernate / orm / 5.0 / javadocs /

Hibernate 5是否反对这个特定的包以及它所包含的所有类?我检查了所有必需的Hibernate 5 jar,但无法在任何地方找到此类 org.hibernate.transaction.JDBCTransactionFactory 。有什么可以在Hibernate 5配置中替代这个类?



我在谷歌搜索方面的成功有限,所以任何答案都将不胜感激!

解决方案

好的,经过进一步研究,我发现Hibernate 5中的事务SPI发生了重大变化!



相应的属性应该是:

 < property name =hibernate.transaction.coordinator_class> org .hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl< /性> 

或者使用这样的简称:

 < property name =hibernate.transaction.coordinator_class> jdbc< / property> 

来自 https://github.com/hibernate/hibernate-orm/blob/5.0/migration-guide.adoc#transactions


交易SPI也作为5.0的一部分重新设计。从用户角度来看,这通常只在配置方面出现。以前的应用程序可以直接通过org.hibernate.Transaction API使用不同的后端事务处理策略。在5.0中添加了一个间接级别。 org.hibernate.Transaction的API实现现在总是相同的。在后端,org.hibernate.Transaction impl与org.hibernate.resource.transaction.TransactionCoordinator进行通信,该代理根据后端事务策略表示给定Session的事务上下文。用户通常不需要关心区别。



更改在这里指出,因为它可能会影响您的引导配置。尽管以前的应用程序会指定hibernate.transaction.factory_class并引用org.hibernate.engine.transaction.spi.TransactionFactory FQN,但 5.0中的新合同是org.hibernate.resource.transaction.TransactionCoordinatorBuilder,并且使用hibernate.transaction.coordinator_class设置。有关其他详细信息,请参阅org.hibernate.cfg.AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY JavaDocs。



可识别以下短名称:jdbc::(非JPA应用程序的默认值)说使用基于JDBC的事务(org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl)jta :: said使用基于JTA的事务(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl )



I am currently working on a project to upgrade from Hibernate 3.x to 5.x. Right now one of the properties in the hibernate configuration xml is as follows :

<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

In Hibernate 5, this particular class defined above as well as the package org.hibernate.transaction does not seem to exist. This class is available in version 3.x however (https://docs.jboss.org/hibernate/envers/3.6/javadocs/org/hibernate/transaction/JDBCTransactionFactory.html). No such class per the Hibernate 5 api docs(https://docs.jboss.org/hibernate/orm/5.0/javadocs/)

Did Hibernate 5 deprecate this particular package along with all of it's contained classes ? I checked in all the required Hibernate 5 jars but am unable to find this class org.hibernate.transaction.JDBCTransactionFactory anywhere. What could be a suitable replacement for this class in Hibernate 5 configuration ?

I've had limited success with google searches so any answers would be appreciated !

解决方案

Okay so upon further research, I found that the Transaction SPI in Hibernate 5 underwent a major change !

The corresponding property should be :

<property name="hibernate.transaction.coordinator_class">org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl</property>

or use the short name like this :

<property name="hibernate.transaction.coordinator_class">jdbc</property>

From https://github.com/hibernate/hibernate-orm/blob/5.0/migration-guide.adoc#transactions

The transaction SPI underwent a major redesign as part of 5.0 as well. From a user perspective this generally only comes into view in terms of configuration. Previously applications would work with the different backend transaction stratagies directly via the org.hibernate.Transaction API. In 5.0 a level of indirection has been added here. The API implementation of org.hibernate.Transaction is always the same now. On the backend, the org.hibernate.Transaction impl talks to a org.hibernate.resource.transaction.TransactionCoordinator which represents the "transactional context" for a given Session according to the backend transaction strategy. Users generally do not need to care about the distinction.

The change is noted here because it might affect your bootstrap configuration. Whereas previously applications would specify hibernate.transaction.factory_class and refer to a org.hibernate.engine.transaction.spi.TransactionFactory FQN, with 5.0 the new contract is org.hibernate.resource.transaction.TransactionCoordinatorBuilder and is specified using the hibernate.transaction.coordinator_class setting. See org.hibernate.cfg.AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY JavaDocs for additional details.

The following short-names are recognized: jdbc::(the default for non-JPA applications) says to use JDBC-based transactions (org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl) jta::says to use JTA-based transactions (org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl)

这篇关于Hibernate 5中的org.hibernate.transaction.JDBCTransactionFactory类在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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