From c6ef23a51c5cfaa2cef32afaffe55ee12203ac37 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Wed, 12 Dec 2012 15:14:38 -0800 Subject: [PATCH] HHH-7860 : Log a warning when embed-xml attribute is used in mappings --- .../java/org/hibernate/cfg/HbmBinder.java | 27 ++++++++++++++++++- .../hibernate/internal/CoreMessageLogger.java | 8 ++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java index 85e8917b8a..e19feea2ed 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java @@ -1403,6 +1403,12 @@ public final class HbmBinder { if ( nodeName == null ) nodeName = node.attributeValue( "name" ); collection.setNodeName( nodeName ); String embed = node.attributeValue( "embed-xml" ); + // sometimes embed is set to the default value when not specified in the mapping, + // so can't seem to determine if an attribute was explicitly set; + // log a warning if embed has a value different from the default. + if ( !StringHelper.isEmpty( embed ) && !"true".equals( embed ) ) { + LOG.embedXmlAttributesNoLongerSupported(); + } collection.setEmbedded( embed==null || "true".equals(embed) ); @@ -1626,6 +1632,12 @@ public final class HbmBinder { manyToOne.setReferencedEntityName( getEntityName( node, mappings ) ); String embed = node.attributeValue( "embed-xml" ); + // sometimes embed is set to the default value when not specified in the mapping, + // so can't seem to determine if an attribute was explicitly set; + // log a warning if embed has a value different from the default. + if ( !StringHelper.isEmpty( embed ) && !"true".equals( embed ) ) { + LOG.embedXmlAttributesNoLongerSupported(); + } manyToOne.setEmbedded( embed == null || "true".equals( embed ) ); String notFound = node.attributeValue( "not-found" ); @@ -1701,7 +1713,14 @@ public final class HbmBinder { initOuterJoinFetchSetting( node, oneToOne ); initLaziness( node, oneToOne, mappings, true ); - oneToOne.setEmbedded( "true".equals( node.attributeValue( "embed-xml" ) ) ); + String embed = node.attributeValue( "embed-xml" ); + // sometimes embed is set to the default value when not specified in the mapping, + // so can't seem to determine if an attribute was explicitly set; + // log a warning if embed has a value different from the default. + if ( !StringHelper.isEmpty( embed ) && !"true".equals( embed ) ) { + LOG.embedXmlAttributesNoLongerSupported(); + } + oneToOne.setEmbedded( "true".equals( embed ) ); Attribute fkNode = node.attribute( "foreign-key" ); if ( fkNode != null ) oneToOne.setForeignKeyName( fkNode.getValue() ); @@ -1729,6 +1748,12 @@ public final class HbmBinder { oneToMany.setReferencedEntityName( getEntityName( node, mappings ) ); String embed = node.attributeValue( "embed-xml" ); + // sometimes embed is set to the default value when not specified in the mapping, + // so can't seem to determine if an attribute was explicitly set; + // log a warning if embed has a value different from the default. + if ( !StringHelper.isEmpty( embed ) && !"true".equals( embed ) ) { + LOG.embedXmlAttributesNoLongerSupported(); + } oneToMany.setEmbedded( embed == null || "true".equals( embed ) ); String notFound = node.attributeValue( "not-found" ); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java index 9a0977558b..c1b09d9855 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java @@ -1601,4 +1601,12 @@ public interface CoreMessageLogger extends BasicLogger { ) void aliasSpecificLockingWithFollowOnLocking(LockMode lockMode); + @LogMessage(level = WARN) + @Message( + value = "embed-xml attributes were intended to be used for DOM4J entity mode. Since that entity mode has been " + + "removed, embed-xml attributes are no longer supported and should be removed from mappings.", + id = 446 + ) + void embedXmlAttributesNoLongerSupported(); + }