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
(cherry picked from commit bf823d440c
)
Conflicts:
hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java
This commit is contained in:
parent
2bf9cadef3
commit
72f238f813
|
@ -57,10 +57,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" );
|
||||
|
|
|
@ -372,6 +372,10 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
|||
return false;
|
||||
}
|
||||
|
||||
protected boolean isCleanupTestDataUsingBulkDelete() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void cleanupTestData() throws Exception {
|
||||
// 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
|
||||
|
@ -379,8 +383,14 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
|||
Transaction transaction = s.beginTransaction();
|
||||
s.getTransaction().begin();
|
||||
try {
|
||||
for ( Object o : s.createQuery( "from java.lang.Object" ).list() ) {
|
||||
s.delete( o );
|
||||
if(isCleanupTestDataUsingBulkDelete()) {
|
||||
s.createQuery( "delete from java.lang.Object" ).executeUpdate();
|
||||
|
||||
}
|
||||
else {
|
||||
for ( Object o : s.createQuery( "from java.lang.Object" ).list() ) {
|
||||
s.delete( o );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
|
Loading…
Reference in New Issue