From 68eb34960bbd7f38e8fbe52c5ea58c5a41af8e32 Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Tue, 11 Oct 2016 11:52:48 -0400 Subject: [PATCH] HHH-11107 - Avoid creating a foreign key when a composite-id contains a many-to-one association for the envers schema. --- .../internal/metadata/BasicMetadataGenerator.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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