Don't add superfluous "and" when there is no discriminator filter

This commit is contained in:
Chris Cranford 2021-03-07 14:11:42 -05:00 committed by Andrea Boriero
parent 21cca2bbc2
commit 79d2569618
1 changed files with 6 additions and 1 deletions

View File

@ -30,6 +30,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.DynamicFilterAliasGenerator;
import org.hibernate.internal.FilterAliasGenerator;
import org.hibernate.internal.util.MarkerObject;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.mapping.Column;
@ -608,7 +609,11 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
@Override
protected String filterFragment(String alias, Set<String> treatAsDeclarations) {
if ( hasWhere() ) {
return discriminatorFilterFragment( alias, treatAsDeclarations ) + " and " + getSQLWhereString( alias );
final String discriminatorFilterFragment = discriminatorFilterFragment( alias, treatAsDeclarations );
if ( StringHelper.isNotEmpty( discriminatorFilterFragment ) ) {
return discriminatorFilterFragment + " and " + getSQLWhereString( alias );
}
return getSQLWhereString( alias );
}
else {
return "";