diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/CollectionMapWithComponentValueTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/CollectionMapWithComponentValueTest.java index 08977218a3..65b50b67ff 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/CollectionMapWithComponentValueTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/CollectionMapWithComponentValueTest.java @@ -157,18 +157,6 @@ public class CollectionMapWithComponentValueTest extends BaseCoreFunctionalTestC return true; } - protected void cleanupTestData() { - Session s = openSession(); - s.getTransaction().begin(); - { - s.createQuery( "from TestEntity" ) - .list() - .forEach( te -> s.delete( te ) ); - } - s.getTransaction().commit(); - s.close(); - } - @Entity(name = "TestEntity") @Table(name = "TEST_ENTITY") public static class TestEntity { 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 03e3a7aae9..c593ded96a 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 @@ -47,6 +47,7 @@ import org.hibernate.testing.cache.CachingRegionFactory; import org.junit.After; import org.junit.Before; +import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.Assert.fail; /** @@ -374,20 +375,11 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { } protected void cleanupTestData() throws Exception { - Session s = openSession(); - Transaction transaction = s.beginTransaction(); - try { - s.createQuery( "delete from java.lang.Object" ).executeUpdate(); - transaction.commit(); - } - catch (Exception e) { - if ( transaction.getStatus().canRollback() ) { - transaction.rollback(); - } - } - finally { - s.close(); - } + // Because of https://hibernate.atlassian.net/browse/HHH-5529, + // we can'trely on a Bulk Delete query which will not clear the link tables in @ElementCollection or unidirectional collections + doInHibernate( this::sessionFactory, s -> { + s.createQuery( "from java.lang.Object" ).list().forEach( s::remove ); + } ); } private void cleanupSession() {