Skip to content
Merged
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 @@ -154,6 +154,7 @@ public Connection close() {
if ( currentBatch != null ) {
JDBC_MESSAGE_LOGGER.closingUnreleasedBatch( hashCode() );
currentBatch.release();
currentBatch = null;
}
}
finally {
Expand All @@ -173,7 +174,10 @@ public Batch getBatch(BatchKey key, Integer batchSize, Supplier<PreparedStatemen
currentBatch.execute();
}
finally {
currentBatch.release();
if ( currentBatch != null ) {
currentBatch.release();
currentBatch = null;
}
}
}
}
Expand All @@ -191,7 +195,10 @@ public void executeBatch() {
currentBatch.execute();
}
finally {
currentBatch.release();
if ( currentBatch != null ) { // abortBatch() might have been called
currentBatch.release();
currentBatch = null;
}
}
}
}
Expand All @@ -204,16 +211,20 @@ public void conditionallyExecuteBatch(BatchKey key) {
currentBatch.execute();
}
finally {
currentBatch.release();
if ( currentBatch != null ) { // abortBatch() might have been called
currentBatch.release();
currentBatch = null;
}
}
}
}

@Override
public void abortBatch() {
if ( currentBatch != null ) {
BATCH_MESSAGE_LOGGER.abortBatch( currentBatch.getKey() .toLoggableString());
BATCH_MESSAGE_LOGGER.abortBatch( currentBatch.getKey().toLoggableString());
currentBatch.release();
currentBatch = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import java.lang.reflect.Field;

import org.hibernate.Session;
import org.hibernate.SessionEventListener;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.jdbc.batch.spi.Batch;
Expand All @@ -30,7 +30,7 @@
* @author Steve Ebersole
*/
@JiraKey( value = "HHH-7689" )
public class BatchingBatchFailureTest extends BaseCoreFunctionalTestCase {
public class BatchingBatchFailureTest extends BaseCoreFunctionalTestCase implements SessionEventListener {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { User.class };
Expand All @@ -45,9 +45,24 @@
configuration.setProperty( AvailableSettings.CHECK_NULLABILITY, false );
}

SessionImplementor session;

Check warning

Code scanning / CodeQL

Field masks field in super class Warning test

This field shadows another field called
session
in a superclass.
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 {
Expand All @@ -67,10 +82,6 @@

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" );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Loading