detect use of @DiscriminatorOptions(force=true) on JOINED with no @DiscriminatorColumn

This commit is contained in:
Gavin 2022-12-25 03:23:03 +01:00 committed by Gavin King
parent 014847f41b
commit 5f0b27fb6a
1 changed files with 9 additions and 3 deletions

View File

@ -644,7 +644,7 @@ public class EntityBinder {
final RootClass rootClass = (RootClass) persistentClass; final RootClass rootClass = (RootClass) persistentClass;
if ( inheritanceState.hasSiblings() if ( inheritanceState.hasSiblings()
|| discriminatorColumn != null && !discriminatorColumn.isImplicit() ) { || discriminatorColumn != null && !discriminatorColumn.isImplicit() ) {
bindDiscriminatorColumnToRootPersistentClass(rootClass, discriminatorColumn, holder ); bindDiscriminatorColumnToRootPersistentClass( rootClass, discriminatorColumn, holder );
rootClass.setForceDiscriminator( isForceDiscriminatorInSelects() ); rootClass.setForceDiscriminator( isForceDiscriminatorInSelects() );
} }
} }
@ -674,10 +674,16 @@ public class EntityBinder {
// the class we're processing is the root of the hierarchy, so // the class we're processing is the root of the hierarchy, so
// let's see if we had a discriminator column (it's perfectly // let's see if we had a discriminator column (it's perfectly
// valid for joined inheritance to not have a discriminator) // valid for joined inheritance to not have a discriminator)
if ( discriminatorColumn != null ) { if ( discriminatorColumn == null ) {
if ( isForceDiscriminatorInSelects() ) {
throw new AnnotationException( "Entity '" + rootClass.getEntityName()
+ "' with 'JOINED' inheritance is annotated '@DiscriminatorOptions(force=true)' but has no discriminator column" );
}
}
else {
// we do have a discriminator column // we do have a discriminator column
if ( state.hasSiblings() || !discriminatorColumn.isImplicit() ) { if ( state.hasSiblings() || !discriminatorColumn.isImplicit() ) {
bindDiscriminatorColumnToRootPersistentClass(rootClass, discriminatorColumn, holder ); bindDiscriminatorColumnToRootPersistentClass( rootClass, discriminatorColumn, holder );
rootClass.setForceDiscriminator( isForceDiscriminatorInSelects() ); rootClass.setForceDiscriminator( isForceDiscriminatorInSelects() );
} }
} }