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
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class QueryAndSQLTest extends BaseCoreFunctionalTestCase {
|
public class QueryAndSQLTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isCleanupTestDataRequired() {
|
protected boolean isCleanupTestDataRequired() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isCleanupTestDataUsingBulkDelete() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNativeQueryWithFormulaAttribute() {
|
public void testNativeQueryWithFormulaAttribute() {
|
||||||
SQLFunction dateFunction = getDialect().getFunctions().get( "current_date" );
|
SQLFunction dateFunction = getDialect().getFunctions().get( "current_date" );
|
||||||
|
|
|
@ -372,6 +372,10 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isCleanupTestDataUsingBulkDelete() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected void cleanupTestData() throws Exception {
|
protected void cleanupTestData() throws Exception {
|
||||||
// Because of https://hibernate.atlassian.net/browse/HHH-5529,
|
// 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
|
// we can'trely on a Bulk Delete query which will not clear the link tables in @ElementCollection or unidirectional collections
|
||||||
|
@ -379,10 +383,16 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
||||||
Transaction transaction = s.beginTransaction();
|
Transaction transaction = s.beginTransaction();
|
||||||
s.getTransaction().begin();
|
s.getTransaction().begin();
|
||||||
try {
|
try {
|
||||||
|
if(isCleanupTestDataUsingBulkDelete()) {
|
||||||
|
s.createQuery( "delete from java.lang.Object" ).executeUpdate();
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
for ( Object o : s.createQuery( "from java.lang.Object" ).list() ) {
|
for ( Object o : s.createQuery( "from java.lang.Object" ).list() ) {
|
||||||
s.delete( o );
|
s.delete( o );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
if ( transaction.getStatus().canRollback() ) {
|
if ( transaction.getStatus().canRollback() ) {
|
||||||
transaction.rollback();
|
transaction.rollback();
|
||||||
|
|
Loading…
Reference in New Issue