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 @@ 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() ) {

View File

@ -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 ) ) {

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;