Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-18961 JtaIsolationDelegate, obtaining connection : NPE when SQLExceptionConversionDelegate#convert returns null #9464

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ private <T> T doTheWork(WorkExecutorVisitable<T> work) {
}
}
catch (SQLException e) {
throw sqlExceptionConverter().apply( e, "unable to obtain isolated JDBC connection" );
final JDBCException jdbcException = sqlExceptionConverter().apply( e, "unable to obtain isolated JDBC connection" );
if ( jdbcException == null ) {
throw new HibernateException( "Unable to obtain isolated JDBC connection", e );
}
throw jdbcException;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.jpa.txn;

import jakarta.transaction.HeuristicMixedException;
import jakarta.transaction.HeuristicRollbackException;
import jakarta.transaction.InvalidTransactionException;
import jakarta.transaction.NotSupportedException;
import jakarta.transaction.RollbackException;
import jakarta.transaction.SystemException;
import jakarta.transaction.Transaction;
import jakarta.transaction.TransactionManager;
import org.hibernate.HibernateException;
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
import org.hibernate.jdbc.AbstractReturningWork;
import org.hibernate.resource.transaction.backend.jta.internal.JtaIsolationDelegate;
import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.jupiter.api.Test;

import java.sql.Connection;
import java.sql.SQLException;

import static org.junit.jupiter.api.Assertions.assertThrowsExactly;

@JiraKey("HHH-18961")
public class JtaObtainConnectionExceptionTest {

@Test
public void testIt() {
final JtaIsolationDelegate isolationDelegate = new JtaIsolationDelegate(
new ObtainConnectionSqlExceptionConnectionAccess(),
null,
new TransactionManagerImpl() );

assertThrowsExactly( HibernateException.class, () ->
isolationDelegate.delegateWork(
new AbstractReturningWork<>() {
@Override
public Object execute(Connection connection) {
return null;
}
},
false
)
);
}

public static class ObtainConnectionSqlExceptionConnectionAccess implements JdbcConnectionAccess {
@Override
public Connection obtainConnection() throws SQLException {
throw new SQLException( "No connection" );
}

@Override
public void releaseConnection(Connection connection) throws SQLException {

}

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

public static class TransactionManagerImpl implements TransactionManager {
@Override
public void begin() throws NotSupportedException, SystemException {

}

@Override
public void commit()
throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
}

@Override
public int getStatus() throws SystemException {
return 0;
}

@Override
public Transaction getTransaction() throws SystemException {
return null;
}

@Override
public void resume(Transaction transaction)
throws InvalidTransactionException, IllegalStateException, SystemException {
}

@Override
public void rollback() throws IllegalStateException, SecurityException, SystemException {

}

@Override
public void setRollbackOnly() throws IllegalStateException, SystemException {

}

@Override
public void setTransactionTimeout(int i) throws SystemException {

}

@Override
public Transaction suspend() throws SystemException {
return null;
}
}
}
Loading