HHH-9282 : Revert HHH-9222 on master
This commit is contained in:
parent
10df4cc79d
commit
873f28f5e6
|
@ -78,49 +78,36 @@ public class DeleteExecutor extends BasicExecutor {
|
||||||
parameterSpecifications = new ArrayList<ParameterSpecification>();
|
parameterSpecifications = new ArrayList<ParameterSpecification>();
|
||||||
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;
|
final CollectionType cType = (CollectionType) type;
|
||||||
}
|
final AbstractCollectionPersister cPersister = (AbstractCollectionPersister) factory
|
||||||
|
|
||||||
// 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 AbstractCollectionPersister cPersister = (AbstractCollectionPersister) factory
|
|
||||||
.getCollectionPersister( cType.getRole() );
|
.getCollectionPersister( cType.getRole() );
|
||||||
final boolean hasCollectionTable = cPersister.isManyToMany()
|
if ( cPersister.isManyToMany() ) {
|
||||||
|| !cPersister.getElementType().isAssociationType();
|
if ( persister.getIdentifierColumnNames().length > 1
|
||||||
if ( !hasCollectionTable ) {
|
&& !dialect.supportsTuplesInSubqueries() ) {
|
||||||
continue;
|
LOG.warn(
|
||||||
}
|
"This dialect is unable to cascade the delete into the many-to-many join table" +
|
||||||
|
|
||||||
if ( persister.getIdentifierColumnNames().length > 1
|
|
||||||
&& !dialect.supportsTuplesInSubqueries() ) {
|
|
||||||
LOG.warn(
|
|
||||||
"This dialect is unable to cascade the delete into the many-to-many join table" +
|
|
||||||
" 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 "
|
||||||
|
+ StringHelper.join( ", ", persister.getIdentifierColumnNames() ) + " from "
|
||||||
|
+ persister.getTableName() + idSubselectWhere + ")";
|
||||||
|
final String where = "(" + StringHelper.join( ", ", cPersister.getKeyColumnNames() )
|
||||||
|
+ ") in " + idSubselect;
|
||||||
|
final Delete delete = new Delete().setTableName( cPersister.getTableName() ).setWhere( where );
|
||||||
|
if ( factory.getSettings().isCommentsEnabled() ) {
|
||||||
|
delete.setComment( "delete FKs in join table" );
|
||||||
|
}
|
||||||
|
deletes.add( delete.toStatementString() );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final String idSubselect = "(select "
|
|
||||||
+ StringHelper.join( ", ", persister.getIdentifierColumnNames() ) + " from "
|
|
||||||
+ persister.getTableName() + idSubselectWhere + ")";
|
|
||||||
final String where = "(" + StringHelper.join( ", ", cPersister.getKeyColumnNames() )
|
|
||||||
+ ") in " + idSubselect;
|
|
||||||
final Delete delete = new Delete().setTableName( cPersister.getTableName() ).setWhere( where );
|
|
||||||
if ( factory.getSettings().isCommentsEnabled() ) {
|
|
||||||
delete.setComment( "bulk delete - collection table clean up (" + cPersister.getRole() + ")" );
|
|
||||||
}
|
|
||||||
deletes.add( delete.toStatementString() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (RecognitionException e) {
|
catch (RecognitionException e) {
|
||||||
|
|
|
@ -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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue