final DeleteStatement deleteStatement = ( DeleteStatement ) walker.getAST();
final AST whereClause = deleteStatement.getWhereClause();
try {
final SqlGenerator gen = new SqlGenerator( factory );
gen.whereClause( whereClause );
parameterSpecifications = gen.getCollectedParameters();
// If many-to-many, delete the FK row in the collection table.
for ( Type type : persister.getPropertyTypes() ) {
if ( type.isCollectionType() ) {
final CollectionType cType = (CollectionType) type;
final AbstractCollectionPersister cPersister = (AbstractCollectionPersister) factory
.getCollectionPersister( cType.getRole() );
if ( cPersister.isManyToMany() ) {
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" +
" the constraints or manually clear the associations prior to deleting the entities." );
}
else {
final String idSubselectWhere = gen.getSQL().length() > 7 ? gen.getSQL() : "";
final String idSubselect = "(select "
+ StringHelper.join( ", ", persister.getIdentifierColumnNames() ) + " from "
+ persister.getTableName() + idSubselectWhere + ")";
final String where = "(" + StringHelper.join( ", ", cPersister.getKeyColumnNames() )
+ ") in " + idSubselect;