HHH-16895 @Check constraint not generated when annotated on entity

This commit is contained in:
Andrea Boriero 2023-07-25 12:27:40 +02:00 committed by Andrea Boriero
parent 9d8d626323
commit c7bafd646a
3 changed files with 15 additions and 10 deletions

View File

@ -2354,6 +2354,12 @@ private void processExportableProducers() {
final Dialect dialect = getDatabase().getJdbcEnvironment().getDialect(); final Dialect dialect = getDatabase().getJdbcEnvironment().getDialect();
for ( PersistentClass entityBinding : entityBindingMap.values() ) { for ( PersistentClass entityBinding : entityBindingMap.values() ) {
entityBinding.assignCheckConstraintsToTable(
dialect,
bootstrapContext.getTypeConfiguration(),
bootstrapContext.getFunctionRegistry()
);
if ( entityBinding.isInherited() ) { if ( entityBinding.isInherited() ) {
continue; continue;
} }
@ -2363,6 +2369,7 @@ private void processExportableProducers() {
dialect, dialect,
(RootClass) entityBinding (RootClass) entityBinding
); );
} }
for ( Collection collection : collectionBindingMap.values() ) { for ( Collection collection : collectionBindingMap.values() ) {

View File

@ -1258,22 +1258,21 @@ public void setSuperMappedSuperclass(MappedSuperclass superMappedSuperclass) {
this.superMappedSuperclass = superMappedSuperclass; this.superMappedSuperclass = superMappedSuperclass;
} }
// End of @MappedSuperclass support public void assignCheckConstraintsToTable(Dialect dialect, TypeConfiguration types, SqmFunctionRegistry functions) {
public void prepareForMappingModel(RuntimeModelCreationContext context) {
if ( !joins.isEmpty() ) {
// we need to deal with references to secondary tables
// in SQL formulas and check constraints
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 ) { for ( CheckConstraint checkConstraint : checkConstraints ) {
container( collectColumnNames( checkConstraint.getConstraint(), dialect, types, functions ) ) container( collectColumnNames( checkConstraint.getConstraint(), dialect, types, functions ) )
.getTable().addCheck( checkConstraint ); .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
final Dialect dialect = context.getDialect();
final TypeConfiguration types = context.getTypeConfiguration();
final SqmFunctionRegistry functions = context.getFunctionRegistry();
// now, move @Formulas to the correct AttributeContainers // now, move @Formulas to the correct AttributeContainers
//TODO: skip this step for hbm.xml //TODO: skip this step for hbm.xml

View File

@ -15,7 +15,6 @@
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor; import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.query.sqm.function.SqmFunctionRegistry; import org.hibernate.query.sqm.function.SqmFunctionRegistry;
import org.hibernate.type.spi.TypeConfiguration; import org.hibernate.type.spi.TypeConfiguration;