diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/JdbcCoordinatorImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/JdbcCoordinatorImpl.java index 851d8fa77a21..341ee7b40507 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/JdbcCoordinatorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/JdbcCoordinatorImpl.java @@ -154,6 +154,7 @@ public Connection close() { if ( currentBatch != null ) { JDBC_MESSAGE_LOGGER.closingUnreleasedBatch( hashCode() ); currentBatch.release(); + currentBatch = null; } } finally { @@ -173,7 +174,10 @@ public Batch getBatch(BatchKey key, Integer batchSize, Supplier[] getAnnotatedClasses() { return new Class[] { User.class }; @@ -45,9 +45,24 @@ protected void configure(Configuration configuration) { configuration.setProperty( AvailableSettings.CHECK_NULLABILITY, false ); } + SessionImplementor session; + Batch batch; + + @Override + public void jdbcExecuteBatchStart() { + try { + Field field = session.getJdbcCoordinator().getClass().getDeclaredField( "currentBatch" ); + field.setAccessible( true ); + batch = (Batch) field.get( session.getJdbcCoordinator() ); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + @Test public void testBasicInsertion() { - Session session = openSession(); + session = sessionFactory().withOptions().eventListeners( this ).openSession(); session.getTransaction().begin(); try { @@ -67,10 +82,6 @@ public void testBasicInsertion() { try { //at this point the transaction is still active but the batch should have been aborted (have to use reflection to get at the field) - SessionImplementor sessionImplementor = (SessionImplementor) session; - Field field = sessionImplementor.getJdbcCoordinator().getClass().getDeclaredField( "currentBatch" ); - field.setAccessible( true ); - Batch batch = (Batch) field.get( sessionImplementor.getJdbcCoordinator() ); if ( batch == null ) { throw new Exception( "Current batch was null" ); } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java index 3cd3df3254e8..40f494475a50 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java @@ -64,7 +64,6 @@ * * @author Steve Ebersole */ -@SuppressWarnings("deprecation") public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { public static final String VALIDATE_DATA_CLEANUP = "hibernate.test.validateDataCleanup";