diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java index 8a2d92f255..6bd7033691 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java @@ -2354,6 +2354,12 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector, final Dialect dialect = getDatabase().getJdbcEnvironment().getDialect(); for ( PersistentClass entityBinding : entityBindingMap.values() ) { + entityBinding.assignCheckConstraintsToTable( + dialect, + bootstrapContext.getTypeConfiguration(), + bootstrapContext.getFunctionRegistry() + ); + if ( entityBinding.isInherited() ) { continue; } @@ -2363,6 +2369,7 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector, dialect, (RootClass) entityBinding ); + } for ( Collection collection : collectionBindingMap.values() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java b/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java index 9a7cbb60bf..fdc9616bc0 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java @@ -1258,23 +1258,22 @@ public abstract class PersistentClass implements IdentifiableTypeClass, Attribut this.superMappedSuperclass = superMappedSuperclass; } - // End of @MappedSuperclass support + public void assignCheckConstraintsToTable(Dialect dialect, TypeConfiguration types, SqmFunctionRegistry functions) { + for ( CheckConstraint checkConstraint : checkConstraints ) { + container( collectColumnNames( checkConstraint.getConstraint(), dialect, types, functions ) ) + .getTable().addCheck( checkConstraint ); + } + } + // End of @MappedSuperclass support public void prepareForMappingModel(RuntimeModelCreationContext context) { if ( !joins.isEmpty() ) { // we need to deal with references to secondary tables - // in SQL formulas and check constraints - + // in SQL formulas final Dialect dialect = context.getDialect(); final TypeConfiguration types = context.getTypeConfiguration(); final SqmFunctionRegistry functions = context.getFunctionRegistry(); - // assign check constraints to the right table - for ( CheckConstraint checkConstraint : checkConstraints ) { - container( collectColumnNames( checkConstraint.getConstraint(), dialect, types, functions ) ) - .getTable().addCheck( checkConstraint ); - } - // now, move @Formulas to the correct AttributeContainers //TODO: skip this step for hbm.xml for ( Property property : new ArrayList<>( properties ) ) { diff --git a/hibernate-core/src/main/java/org/hibernate/sql/Template.java b/hibernate-core/src/main/java/org/hibernate/sql/Template.java index 2543390f87..3924b5189b 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/Template.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/Template.java @@ -15,7 +15,6 @@ import java.util.StringTokenizer; import org.hibernate.HibernateException; import org.hibernate.dialect.Dialect; -import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.query.sqm.function.SqmFunctionDescriptor; import org.hibernate.query.sqm.function.SqmFunctionRegistry; import org.hibernate.type.spi.TypeConfiguration;