HHH-9282 : Revert HHH-9222 on master

This commit is contained in:
Gail Badner 2014-07-09 22:45:00 -07:00
parent 10df4cc79d
commit 873f28f5e6
3 changed files with 38 additions and 72 deletions

View File

@ -79,28 +79,13 @@ public class DeleteExecutor extends BasicExecutor {
idSubselectWhere = ""; idSubselectWhere = "";
} }
// find plural attributes defined for the entity being deleted... // If many-to-many, delete the FK row in the collection table.
for ( Type type : persister.getPropertyTypes() ) { for ( Type type : persister.getPropertyTypes() ) {
if ( ! type.isCollectionType() ) { if ( type.isCollectionType() ) {
continue;
}
// if the plural attribute maps to a "collection table" we need
// to remove the rows from that table corresponding to any
// owners we are about to delete. "collection table" is
// (unfortunately) indicated in a number of ways, but here we
// are mainly concerned with:
// 1) many-to-many mappings
// 2) basic collection mappings
final CollectionType cType = (CollectionType) type; final CollectionType cType = (CollectionType) type;
final AbstractCollectionPersister cPersister = (AbstractCollectionPersister) factory final AbstractCollectionPersister cPersister = (AbstractCollectionPersister) factory
.getCollectionPersister( cType.getRole() ); .getCollectionPersister( cType.getRole() );
final boolean hasCollectionTable = cPersister.isManyToMany() if ( cPersister.isManyToMany() ) {
|| !cPersister.getElementType().isAssociationType();
if ( !hasCollectionTable ) {
continue;
}
if ( persister.getIdentifierColumnNames().length > 1 if ( persister.getIdentifierColumnNames().length > 1
&& !dialect.supportsTuplesInSubqueries() ) { && !dialect.supportsTuplesInSubqueries() ) {
LOG.warn( LOG.warn(
@ -108,9 +93,8 @@ public class DeleteExecutor extends BasicExecutor {
" when the entity has multiple primary keys. Either properly setup cascading on" + " when the entity has multiple primary keys. Either properly setup cascading on" +
" the constraints or manually clear the associations prior to deleting the entities." " the constraints or manually clear the associations prior to deleting the entities."
); );
continue;
} }
else {
final String idSubselect = "(select " final String idSubselect = "(select "
+ StringHelper.join( ", ", persister.getIdentifierColumnNames() ) + " from " + StringHelper.join( ", ", persister.getIdentifierColumnNames() ) + " from "
+ persister.getTableName() + idSubselectWhere + ")"; + persister.getTableName() + idSubselectWhere + ")";
@ -118,11 +102,14 @@ public class DeleteExecutor extends BasicExecutor {
+ ") in " + idSubselect; + ") in " + idSubselect;
final Delete delete = new Delete().setTableName( cPersister.getTableName() ).setWhere( where ); final Delete delete = new Delete().setTableName( cPersister.getTableName() ).setWhere( where );
if ( factory.getSettings().isCommentsEnabled() ) { if ( factory.getSettings().isCommentsEnabled() ) {
delete.setComment( "bulk delete - collection table clean up (" + cPersister.getRole() + ")" ); delete.setComment( "delete FKs in join table" );
} }
deletes.add( delete.toStatementString() ); deletes.add( delete.toStatementString() );
} }
} }
}
}
}
catch (RecognitionException e) { catch (RecognitionException e) {
throw new HibernateException( "Unable to delete the FKs in the join table!", e ); throw new HibernateException( "Unable to delete the FKs in the join table!", e );
} }

View File

@ -83,39 +83,17 @@ public class TableBasedDeleteHandlerImpl
final String idSubselect = generateIdSubselect( targetedPersister ); final String idSubselect = generateIdSubselect( targetedPersister );
deletes = new ArrayList<String>(); deletes = new ArrayList<String>();
// find plural attributes defined for the entity being deleted... // If many-to-many, delete the FK row in the collection table.
// // This partially overlaps with DeleteExecutor, but it instead uses the temp table in the idSubselect.
// NOTE : this partially overlaps with DeleteExecutor, but it instead
// uses the temp table in the idSubselect.
for ( Type type : targetedPersister.getPropertyTypes() ) { for ( Type type : targetedPersister.getPropertyTypes() ) {
if ( ! type.isCollectionType() ) { if ( type.isCollectionType() ) {
continue; CollectionType cType = (CollectionType) type;
AbstractCollectionPersister cPersister = (AbstractCollectionPersister)factory.getCollectionPersister( cType.getRole() );
if ( cPersister.isManyToMany() ) {
deletes.add( generateDelete( cPersister.getTableName(),
cPersister.getKeyColumnNames(), idSubselect, "bulk delete - m2m join table cleanup"));
} }
final CollectionType cType = (CollectionType) type;
final AbstractCollectionPersister cPersister = (AbstractCollectionPersister)factory.getCollectionPersister( cType.getRole() );
// if the plural attribute maps to a "collection table" we need
// to remove the rows from that table corresponding to any
// owners we are about to delete. "collection table" is
// (unfortunately) indicated in a number of ways, but here we
// are mainly concerned with:
// 1) many-to-many mappings
// 2) basic collection mappings
final boolean hasCollectionTable = cPersister.isManyToMany()
|| !cPersister.getElementType().isAssociationType();
if ( !hasCollectionTable ) {
continue;
} }
deletes.add(
generateDelete(
cPersister.getTableName(),
cPersister.getKeyColumnNames(),
idSubselect,
"bulk delete - collection table clean up (" + cPersister.getRole() + ")"
)
);
} }
String[] tableNames = targetedPersister.getConstraintOrderedTableNameClosure(); String[] tableNames = targetedPersister.getConstraintOrderedTableNameClosure();
@ -125,7 +103,7 @@ public class TableBasedDeleteHandlerImpl
// the difficulty is the ordering of the tables here vs the cascade attributes on the persisters -> // the difficulty is the ordering of the tables here vs the cascade attributes on the persisters ->
// the table info gotten here should really be self-contained (i.e., a class representation // the table info gotten here should really be self-contained (i.e., a class representation
// defining all the needed attributes), then we could then get an array of those // defining all the needed attributes), then we could then get an array of those
deletes.add( generateDelete( tableNames[i], columnNames[i], idSubselect, "bulk delete" ) ); deletes.add( generateDelete( tableNames[i], columnNames[i], idSubselect, "bulk delete"));
} }
} }

View File

@ -46,6 +46,7 @@ import org.hibernate.jdbc.Work;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.testing.DialectChecks; import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.FailureExpectedWithNewUnifiedXsd; import org.hibernate.testing.FailureExpectedWithNewUnifiedXsd;
import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.RequiresDialectFeature;
@ -1426,7 +1427,7 @@ public class BulkManipulationTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
@TestForIssue( jiraKey = "HHH-9222" ) @FailureExpected( jiraKey = "HHH-9282", message = "failed because HHH-9222 was reverted by HHH-9282")
public void testBulkDeleteOfEntityWithElementCollection() { public void testBulkDeleteOfEntityWithElementCollection() {
// set up test data // set up test data
{ {
@ -1495,7 +1496,7 @@ public class BulkManipulationTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
@TestForIssue( jiraKey = "HHH-9222" ) @FailureExpected( jiraKey = "HHH-9282", message = "failed because HHH-9222 was reverted by HHH-9282")
public void testBulkDeleteOfMultiTableEntityWithElementCollection() { public void testBulkDeleteOfMultiTableEntityWithElementCollection() {
// set up test data // set up test data
{ {