From a234ea600bdab323adc6cf2059b8ae81b1f0f048 Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Wed, 17 May 2017 23:40:34 -0400 Subject: [PATCH] HHH-11463 - Avoid creating foreign keys from audit schema to non-audit schema. --- .../internal/metadata/MetadataTools.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/MetadataTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/MetadataTools.java index 90ee1e1eef..cf38c7aa46 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/MetadataTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/MetadataTools.java @@ -333,6 +333,19 @@ public final class MetadataTools { if ( changeToKey ) { property.setName( "key-" + property.getName() ); + + // HHH-11463 when cloning a many-to-one to be a key-many-to-one, the FK attribute + // should be explicitly set to 'none' or added to be 'none' to avoid issues with + // making references to the main schema. + if ( property.getName().equals( "key-many-to-one" ) ) { + final Attribute foreignKey = property.attribute( "foreign-key" ); + if ( foreignKey == null ) { + property.addAttribute( "foreign-key", "none" ); + } + else { + foreignKey.setValue( "none" ); + } + } } if ( "property".equals( property.getName() ) ) {