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:
parent
70db5e4241
commit
fc4665707d
|
@ -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 {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue