From fc81e644637ba3e29b48b8006c1001b7949977bf Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 10 Sep 2025 18:05:44 +0200 Subject: [PATCH 1/2] set the current batch to null after releasing it this silences a bunch of noisy "Aborting batch" log messages --- .../jdbc/internal/JdbcCoordinatorImpl.java | 19 +++++++++++--- .../test/batch/BatchingBatchFailureTest.java | 25 +++++++++++++------ 2 files changed, 33 insertions(+), 11 deletions(-) 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" ); } From 7b4ed96d95118a77aee88d326474114688be07fd Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 10 Sep 2025 18:28:16 +0200 Subject: [PATCH 2/2] remove obsolete @SuppressWarnings("deprecation") --- .../org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java | 1 - 1 file changed, 1 deletion(-) 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";