Skip to content

Commit c7bafd6

Browse files
committed
HHH-16895 @check constraint not generated when annotated on entity
1 parent 9d8d626 commit c7bafd6

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,12 @@ private void processExportableProducers() {
23542354
final Dialect dialect = getDatabase().getJdbcEnvironment().getDialect();
23552355

23562356
for ( PersistentClass entityBinding : entityBindingMap.values() ) {
2357+
entityBinding.assignCheckConstraintsToTable(
2358+
dialect,
2359+
bootstrapContext.getTypeConfiguration(),
2360+
bootstrapContext.getFunctionRegistry()
2361+
);
2362+
23572363
if ( entityBinding.isInherited() ) {
23582364
continue;
23592365
}
@@ -2363,6 +2369,7 @@ private void processExportableProducers() {
23632369
dialect,
23642370
(RootClass) entityBinding
23652371
);
2372+
23662373
}
23672374

23682375
for ( Collection collection : collectionBindingMap.values() ) {

hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,23 +1258,22 @@ public void setSuperMappedSuperclass(MappedSuperclass superMappedSuperclass) {
12581258
this.superMappedSuperclass = superMappedSuperclass;
12591259
}
12601260

1261-
// End of @MappedSuperclass support
1261+
public void assignCheckConstraintsToTable(Dialect dialect, TypeConfiguration types, SqmFunctionRegistry functions) {
1262+
for ( CheckConstraint checkConstraint : checkConstraints ) {
1263+
container( collectColumnNames( checkConstraint.getConstraint(), dialect, types, functions ) )
1264+
.getTable().addCheck( checkConstraint );
1265+
}
1266+
}
12621267

1268+
// End of @MappedSuperclass support
12631269
public void prepareForMappingModel(RuntimeModelCreationContext context) {
12641270
if ( !joins.isEmpty() ) {
12651271
// we need to deal with references to secondary tables
1266-
// in SQL formulas and check constraints
1267-
1272+
// in SQL formulas
12681273
final Dialect dialect = context.getDialect();
12691274
final TypeConfiguration types = context.getTypeConfiguration();
12701275
final SqmFunctionRegistry functions = context.getFunctionRegistry();
12711276

1272-
// assign check constraints to the right table
1273-
for ( CheckConstraint checkConstraint : checkConstraints ) {
1274-
container( collectColumnNames( checkConstraint.getConstraint(), dialect, types, functions ) )
1275-
.getTable().addCheck( checkConstraint );
1276-
}
1277-
12781277
// now, move @Formulas to the correct AttributeContainers
12791278
//TODO: skip this step for hbm.xml
12801279
for ( Property property : new ArrayList<>( properties ) ) {

hibernate-core/src/main/java/org/hibernate/sql/Template.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import org.hibernate.HibernateException;
1717
import org.hibernate.dialect.Dialect;
18-
import org.hibernate.engine.spi.SessionFactoryImplementor;
1918
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
2019
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
2120
import org.hibernate.type.spi.TypeConfiguration;

0 commit comments

Comments
 (0)