HHH-12622 - ignore markRollbackOnly on inactive transactions
This commit is contained in:
parent
6be4001022
commit
9081aaf23b
|
@ -194,8 +194,12 @@ public class TransactionImpl implements TransactionImplementor {
|
|||
// JPA-defined API. In our opinion it is much more user-friendly to
|
||||
// always allow user/integration to indicate that the transaction
|
||||
// should not be allowed to commit.
|
||||
//
|
||||
// However.. should only "do something" on an active transaction
|
||||
if ( isActive() ) {
|
||||
internalGetTransactionDriverControl().markRollbackOnly();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRollbackOnly() {
|
||||
|
|
|
@ -67,6 +67,41 @@ public class EntityTransactionTests extends BaseUnitTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarkRollbackOnlyNoTransaction() {
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.JPA_TRANSACTION_COMPLIANCE, "true" )
|
||||
.build();
|
||||
|
||||
try {
|
||||
final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) new MetadataSources( ssr )
|
||||
.buildMetadata()
|
||||
.buildSessionFactory();
|
||||
|
||||
try {
|
||||
inSession(
|
||||
sessionFactory,
|
||||
session -> {
|
||||
final Transaction transaction = session.getTransaction();
|
||||
assertFalse( transaction.isActive() );
|
||||
|
||||
// should just happen silently because there is no transaction
|
||||
transaction.markRollbackOnly();
|
||||
|
||||
transaction.begin();
|
||||
transaction.commit();
|
||||
}
|
||||
);
|
||||
}
|
||||
finally {
|
||||
sessionFactory.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( ssr );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetRollbackOnlyOutcomeExpectations() {
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
|
|
|
@ -223,6 +223,8 @@ public class QueryApiTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
session -> {
|
||||
try {
|
||||
assertFalse( session.getTransaction().isActive() );
|
||||
session.getTransaction().begin();
|
||||
|
||||
// Query
|
||||
session.createQuery( "invalid" ).list();
|
||||
fail( "expecting failure" );
|
||||
|
|
Loading…
Reference in New Issue