Skip to content

Commit 2883cb8

Browse files
committed
HHH-7860 : Log a warning when embed-xml attribute is used in mappings
1 parent dc3283f commit 2883cb8

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,12 @@ public static void bindCollection(Element node, Collection collection, String cl
14041404
if ( nodeName == null ) nodeName = node.attributeValue( "name" );
14051405
collection.setNodeName( nodeName );
14061406
String embed = node.attributeValue( "embed-xml" );
1407+
// sometimes embed is set to the default value when not specified in the mapping,
1408+
// so can't seem to determine if an attribute was explicitly set;
1409+
// log a warning if embed has a value different from the default.
1410+
if ( !StringHelper.isEmpty( embed ) && !"true".equals( embed ) ) {
1411+
LOG.embedXmlAttributesNoLongerSupported();
1412+
}
14071413
collection.setEmbedded( embed==null || "true".equals(embed) );
14081414

14091415

@@ -1627,6 +1633,12 @@ public static void bindManyToOne(Element node, ManyToOne manyToOne, String path,
16271633
manyToOne.setReferencedEntityName( getEntityName( node, mappings ) );
16281634

16291635
String embed = node.attributeValue( "embed-xml" );
1636+
// sometimes embed is set to the default value when not specified in the mapping,
1637+
// so can't seem to determine if an attribute was explicitly set;
1638+
// log a warning if embed has a value different from the default.
1639+
if ( !StringHelper.isEmpty( embed ) && !"true".equals( embed ) ) {
1640+
LOG.embedXmlAttributesNoLongerSupported();
1641+
}
16301642
manyToOne.setEmbedded( embed == null || "true".equals( embed ) );
16311643

16321644
String notFound = node.attributeValue( "not-found" );
@@ -1702,7 +1714,14 @@ public static void bindOneToOne(Element node, OneToOne oneToOne, String path, bo
17021714
initOuterJoinFetchSetting( node, oneToOne );
17031715
initLaziness( node, oneToOne, mappings, true );
17041716

1705-
oneToOne.setEmbedded( "true".equals( node.attributeValue( "embed-xml" ) ) );
1717+
String embed = node.attributeValue( "embed-xml" );
1718+
// sometimes embed is set to the default value when not specified in the mapping,
1719+
// so can't seem to determine if an attribute was explicitly set;
1720+
// log a warning if embed has a value different from the default.
1721+
if ( !StringHelper.isEmpty( embed ) && !"true".equals( embed ) ) {
1722+
LOG.embedXmlAttributesNoLongerSupported();
1723+
}
1724+
oneToOne.setEmbedded( "true".equals( embed ) );
17061725

17071726
Attribute fkNode = node.attribute( "foreign-key" );
17081727
if ( fkNode != null ) oneToOne.setForeignKeyName( fkNode.getValue() );
@@ -1730,6 +1749,12 @@ public static void bindOneToMany(Element node, OneToMany oneToMany, Mappings map
17301749
oneToMany.setReferencedEntityName( getEntityName( node, mappings ) );
17311750

17321751
String embed = node.attributeValue( "embed-xml" );
1752+
// sometimes embed is set to the default value when not specified in the mapping,
1753+
// so can't seem to determine if an attribute was explicitly set;
1754+
// log a warning if embed has a value different from the default.
1755+
if ( !StringHelper.isEmpty( embed ) && !"true".equals( embed ) ) {
1756+
LOG.embedXmlAttributesNoLongerSupported();
1757+
}
17331758
oneToMany.setEmbedded( embed == null || "true".equals( embed ) );
17341759

17351760
String notFound = node.attributeValue( "not-found" );

hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,4 +1601,12 @@ void cannotResolveNonNullableTransientDependencies(String transientEntityString,
16011601
)
16021602
void aliasSpecificLockingWithFollowOnLocking(LockMode lockMode);
16031603

1604+
@LogMessage(level = WARN)
1605+
@Message(
1606+
value = "embed-xml attributes were intended to be used for DOM4J entity mode. Since that entity mode has been " +
1607+
"removed, embed-xml attributes are no longer supported and should be removed from mappings.",
1608+
id = 446
1609+
)
1610+
void embedXmlAttributesNoLongerSupported();
1611+
16041612
}

0 commit comments

Comments
 (0)