Skip to content

Commit

Permalink
HHH-18728 - Allow mixed discriminator-value mappings for ANY
Browse files Browse the repository at this point in the history
HHH-18729 - Allow custom strategy for implicit discriminator-value determination for ANY
  • Loading branch information
sebersole committed Oct 28, 2024
1 parent 9397b1e commit f858d39
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import java.util.function.Consumer;
import java.util.function.Function;

import static org.hibernate.persister.entity.DiscriminatorHelper.NOT_NULL_DISCRIMINATOR;
import static org.hibernate.persister.entity.DiscriminatorHelper.NULL_DISCRIMINATOR;

/**
* @author Steve Ebersole
*/
Expand Down Expand Up @@ -60,6 +63,14 @@ private ImplicitDiscriminatorStrategy resolveImplicitValueStrategy(ImplicitDiscr
return FullNameImplicitDiscriminatorStrategy.FULL_NAME_STRATEGY;
}
}
else {
if ( explicitValueMappings.containsKey( NOT_NULL_DISCRIMINATOR ) ) {
if ( implicitValueStrategy != null ) {
// we will ultimately not know how to handle "implicit" values which are non-null
throw new HibernateException( "Illegal use of ImplicitDiscriminatorStrategy with explicit non-null discriminator mapping: " + discriminatorRole.getFullPath() );
}
}
}
return implicitValueStrategy;
}

Expand All @@ -80,6 +91,10 @@ public Map<String, DiscriminatorValueDetails> getDetailsByEntityName() {

@Override
public DiscriminatorValueDetails getDetailsForDiscriminatorValue(Object relationalValue) {
if ( relationalValue == null ) {
return detailsByValue.get( NULL_DISCRIMINATOR );
}

final DiscriminatorValueDetails existing = detailsByValue.get( relationalValue );
if ( existing != null ) {
return existing;
Expand Down Expand Up @@ -109,6 +124,11 @@ else if ( getRelationalJavaType() instanceof CharacterJavaType ) {
}
}

final DiscriminatorValueDetails nonNullMatch = detailsByValue.get( NOT_NULL_DISCRIMINATOR );
if ( nonNullMatch != null ) {
return nonNullMatch;
}

throw new HibernateException( "Unknown discriminator value (" + discriminatorRole.getFullPath() + ") : " + relationalValue );
}

Expand Down

0 comments on commit f858d39

Please sign in to comment.