Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where did the class org.hibernate.transaction.JDBCTransactionFactory go in Hibernate 5?

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 !

like image 328
Suketu Bhuta Avatar asked Mar 27 '17 23:03

Suketu Bhuta


1 Answers

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)

like image 80
Suketu Bhuta Avatar answered Nov 02 '22 04:11

Suketu Bhuta