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 22bc539298
commit 7d9621c8d9
3 changed files with 15 additions and 10 deletions

View File

@ -2353,6 +2353,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;
}
@ -2362,6 +2368,7 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector,
dialect,
(RootClass) entityBinding
);
}
for ( Collection collection : collectionBindingMap.values() ) {

View File

@ -1258,23 +1258,22 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
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 ) ) {

View File

@ -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;