将自定义JdbcTransaction从休眠4迁移到5

时间:2019-05-31 12:24:19

标签: hibernate

我必须将不再在办公室的人制作的旧库迁移到休眠5中。 我看到此代码包含此类:

public class CustomTransaction extends JdbcTransaction {

private Stack<Savepoint> savepoints = new Stack<>();

protected CustomTransaction(TransactionCoordinator transactionCoordinator) {
    super(transactionCoordinator);
}

public void pushSavepoint() throws SQLException {
    Connection connection = transactionCoordinator().getJdbcCoordinator().getLogicalConnection().getConnection();
    Savepoint savepoint = connection.setSavepoint();
    savepoints.push(savepoint);
}

public Savepoint peekSavepoint() {
    return savepoints.isEmpty() ? null : savepoints.peek();
}

}

从以下实例化的

public final class CustomTransactionFactory implements TransactionFactory<JdbcTransaction> {

@Override
public JdbcTransaction createTransaction(TransactionCoordinator transactionCoordinator) {
    return new CustomTransaction(transactionCoordinator);
}

@Override
public boolean canBeDriver() {
    return true;
}

@Override
public ConnectionReleaseMode getDefaultReleaseMode() {
    return ConnectionReleaseMode.ON_CLOSE;
}

@Override
public boolean compatibleWithJtaSynchronization() {
    return false;
}

@Override
public boolean isJoinableJtaTransaction(TransactionCoordinator transactionCoordinator, JdbcTransaction transaction) {
    return false;
}
}

阅读从休眠4到5的迁移指南时,我发现我需要更改:

hibernate.transaction.factory_class=org.hibernate.transaction.JDBCTransactionFactory

进入      hibernate.transaction.coordinator_class = org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl

在我的情况下,最初的类不是JDBCTransactionFactory,而是扩展它的类,并且如果我尝试扩展JdbcResourceLocalTransactionCoordinatorImpl,就像第一次尝试时那样,您会发现这些类与另一个无关。

在这种情况下,我应该用什么代替JDBCTransactionFactory?在此核心创建自定义事务并将存储点存储在其中之前。现在,我看到无法创建自定义交易。

0 个答案:

没有答案