HHH-10996 - The cleanupTestData utility has issues with link tables
Use bulk delete in certain situations like when we have a @Formula annotation that takes an SQL function which is not supported by the currently running DB
This commit is contained in:
parent
714ba62158
commit
bf823d440c
|
@ -52,10 +52,17 @@ import static org.junit.Assert.fail;
|
|||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class QueryAndSQLTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected boolean isCleanupTestDataRequired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCleanupTestDataUsingBulkDelete() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNativeQueryWithFormulaAttribute() {
|
||||
SQLFunction dateFunction = getDialect().getFunctions().get( "current_date" );
|
||||
|
|
|
@ -373,13 +373,23 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
|||
return false;
|
||||
}
|
||||
|
||||
protected boolean isCleanupTestDataUsingBulkDelete() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void cleanupTestData() throws Exception {
|
||||
if(isCleanupTestDataUsingBulkDelete()) {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
s.createQuery( "delete from java.lang.Object" ).executeUpdate();
|
||||
} );
|
||||
} else {
|
||||
// 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() {
|
||||
if ( session != null && ! ( (SessionImplementor) session ).isClosed() ) {
|
||||
|
|
Loading…
Reference in New Issue