mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-09 20:54:46 +00:00
HHH-16616 Apply discriminator by pruning table group
Also, only apply the discriminator for loads since in queries the pruning is already handled by the entity name usage logic.
This commit is contained in:
parent
3ae0a0e430
commit
0914fba014
@ -300,12 +300,16 @@ protected void applyWhereFragments(
|
||||
SqlAstCreationState astCreationState) {
|
||||
super.applyWhereFragments( predicateConsumer, alias, tableGroup, astCreationState );
|
||||
|
||||
getElementPersisterInternal().applyDiscriminator(
|
||||
predicateConsumer,
|
||||
alias,
|
||||
tableGroup,
|
||||
astCreationState
|
||||
);
|
||||
if ( !astCreationState.supportsEntityNameUsage() ) {
|
||||
// We only need to apply discriminator for loads, since queries with joined
|
||||
// inheritance subtypes are already filtered by the entity name usage logic
|
||||
getElementPersisterInternal().applyDiscriminator(
|
||||
predicateConsumer,
|
||||
alias,
|
||||
tableGroup,
|
||||
astCreationState
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -14,6 +14,7 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
@ -3013,7 +3014,7 @@ public void applyDiscriminator(
|
||||
TableGroup tableGroup,
|
||||
SqlAstCreationState creationState) {
|
||||
if ( needsDiscriminator() ) {
|
||||
predicateConsumer.accept( createDiscriminatorPredicate( alias, tableGroup, creationState ) );
|
||||
pruneForSubclasses( tableGroup, Collections.singletonMap( getEntityName(), EntityNameUse.TREAT ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3042,6 +3042,11 @@ private void registerPathAttributeEntityNameUsage(SqmPath<?> sqmPath, TableGroup
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsEntityNameUsage() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerEntityNameUsage(
|
||||
TableGroup tableGroup,
|
||||
|
@ -42,4 +42,9 @@ default void registerEntityNameUsage(
|
||||
String hibernateEntityName) {
|
||||
// No-op
|
||||
}
|
||||
|
||||
@Internal
|
||||
default boolean supportsEntityNameUsage() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ public List<String> getAffectedTableNames() {
|
||||
|
||||
@Override
|
||||
public boolean containsAffectedTableName(String requestedName) {
|
||||
return isEmpty( requestedName ) || getTableExpression().equals( requestedName );
|
||||
return isEmpty( requestedName ) || getTableExpression().contains( requestedName );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user