HHH-15060 - Associations with @NotFound should always be left joined when de-referenced in HQL/Criteria

- `@NotFound` no longer exports a physical foreign-key
This commit is contained in:
Steve Ebersole 2022-02-03 14:14:40 -06:00
parent 5febc70134
commit 1f84125e44
2 changed files with 15 additions and 5 deletions

View File

@ -3462,10 +3462,20 @@ public final class AnnotationBinder {
JoinColumns joinColumns,
MetadataBuildingContext context) {
final boolean noConstraintByDefault = context.getBuildingOptions().isNoConstraintByDefault();
if ( ( joinColumn != null && ( joinColumn.foreignKey().value() == ConstraintMode.NO_CONSTRAINT
|| joinColumn.foreignKey().value() == ConstraintMode.PROVIDER_DEFAULT && noConstraintByDefault ) )
|| ( joinColumns != null && ( joinColumns.foreignKey().value() == ConstraintMode.NO_CONSTRAINT
|| joinColumns.foreignKey().value() == ConstraintMode.PROVIDER_DEFAULT && noConstraintByDefault ) ) ) {
final NotFound notFoundAnn= property.getAnnotation( NotFound.class );
if ( notFoundAnn != null ) {
// supersedes all others
value.setForeignKeyName( "none" );
}
else if ( joinColumn != null && (
joinColumn.foreignKey().value() == ConstraintMode.NO_CONSTRAINT
|| ( joinColumn.foreignKey().value() == ConstraintMode.PROVIDER_DEFAULT && noConstraintByDefault ) ) ) {
value.setForeignKeyName( "none" );
}
else if ( joinColumns != null && (
joinColumns.foreignKey().value() == ConstraintMode.NO_CONSTRAINT
|| ( joinColumns.foreignKey().value() == ConstraintMode.PROVIDER_DEFAULT && noConstraintByDefault ) ) ) {
value.setForeignKeyName( "none" );
}
else {

View File

@ -91,7 +91,7 @@ public class NotFoundLogicalOneToOneTest extends BaseCoreFunctionalTestCase {
}
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
// @JoinColumn(foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
@NotFound(action = NotFoundAction.IGNORE)
public Currency getCurrency() {
return currency;