From 2883cb85c37fbd6fd956f750fc8082aaa9be0fa1 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Wed, 12 Dec 2012 16:06:03 -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 6692db88f7..624552cacb 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java @@ -1404,6 +1404,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) ); @@ -1627,6 +1633,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" ); @@ -1702,7 +1714,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() ); @@ -1730,6 +1749,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 f4e10225c4..5a450df3f4 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(); + }