diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/BasicMetadataGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/BasicMetadataGenerator.java index ecfc7282ce..e60de2c936 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/BasicMetadataGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/BasicMetadataGenerator.java @@ -126,6 +126,14 @@ public final class BasicMetadataGenerator { final Element manyToOneElement = parent.addElement( mapper != null ? "many-to-one" : "key-many-to-one" ); manyToOneElement.addAttribute( "name", propertyAuditingData.getName() ); manyToOneElement.addAttribute( "class", type.getName() ); + + // HHH-11107 + // Use FK hbm magic value 'none' to skip making foreign key constraints between the Envers + // schema and the base table schema when a @ManyToOne is present in an identifier. + if ( mapper == null ) { + manyToOneElement.addAttribute( "foreign-key", "none" ); + } + MetadataTools.addColumns( manyToOneElement, value.getColumnIterator() ); // A null mapper means that we only want to add xml mappings