From fc4665707d29594f0d3fd6c2643a573d04888268 Mon Sep 17 00:00:00 2001 From: Vlad Mihalcea Date: Wed, 27 Jul 2016 16:13:35 +0300 Subject: [PATCH] HHH-10996 - The cleanupTestData utility has issues with link tables (cherry picked from commit 8f5ba32990d291057c7acd2a5170293cabcbf4ab) Conflicts: hibernate-core/src/test/java/org/hibernate/test/hql/CollectionMapWithComponentValueTest.java --- .../CollectionMapWithComponentValueTest.java | 12 ----------- .../junit4/BaseCoreFunctionalTestCase.java | 20 ++++++------------- 2 files changed, 6 insertions(+), 26 deletions(-) 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() {