HHH-15761 Validate identifier generator

Having tyhe validation in a separate method, make it possible
to extend the class without causing a StackOverflow exception
when overriding the getter.
This commit is contained in:
Davide D'Alto 2022-11-28 20:51:19 +00:00 committed by Davide D'Alto
parent 7e36605a75
commit e84bf71b7f
1 changed files with 8 additions and 7 deletions

View File

@ -109,15 +109,9 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
final EntityDataAccess cacheAccessStrategy, final EntityDataAccess cacheAccessStrategy,
final NaturalIdDataAccess naturalIdRegionAccessStrategy, final NaturalIdDataAccess naturalIdRegionAccessStrategy,
final RuntimeModelCreationContext creationContext) throws HibernateException { final RuntimeModelCreationContext creationContext) throws HibernateException {
super( persistentClass, cacheAccessStrategy, naturalIdRegionAccessStrategy, creationContext ); super( persistentClass, cacheAccessStrategy, naturalIdRegionAccessStrategy, creationContext );
if ( getGenerator() instanceof IdentityGenerator ) { validateGenerator();
throw new MappingException(
"Cannot use identity column key generation with <union-subclass> mapping for: " +
getEntityName()
);
}
final SessionFactoryImplementor factory = creationContext.getSessionFactory(); final SessionFactoryImplementor factory = creationContext.getSessionFactory();
final Dialect dialect = factory.getJdbcServices().getDialect(); final Dialect dialect = factory.getJdbcServices().getDialect();
@ -246,6 +240,13 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
postConstruct( creationContext.getMetadata() ); postConstruct( creationContext.getMetadata() );
} }
protected void validateGenerator() {
if ( getGenerator() instanceof IdentityGenerator ) {
throw new MappingException( "Cannot use identity column key generation with <union-subclass> mapping for: " + getEntityName()
);
}
}
@Override @Override
public boolean containsTableReference(String tableExpression) { public boolean containsTableReference(String tableExpression) {
for ( String subclassTableExpression : subclassTableExpressions ) { for ( String subclassTableExpression : subclassTableExpressions ) {