HHH-10996 - The cleanupTestData utility has issues with link tables

(cherry picked from commit 8f5ba32990)

Conflicts:
	hibernate-core/src/test/java/org/hibernate/test/hql/CollectionMapWithComponentValueTest.java
This commit is contained in:
Vlad Mihalcea 2016-07-27 16:13:35 +03:00 committed by Gail Badner
parent 70db5e4241
commit fc4665707d
2 changed files with 6 additions and 26 deletions

View File

@ -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 {

View File

@ -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() {