Skip to content

Commit 91cd767

Browse files
committed
HHH-10115 - HHH90000003: Use of DOM4J entity-mode is considered deprecated
1 parent ff7644f commit 91cd767

File tree

8 files changed

+163
-6
lines changed

8 files changed

+163
-6
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,7 +1884,7 @@ public String getPropertyAccessorName() {
18841884
attribute
18851885
);
18861886

1887-
if ( StringHelper.isNotEmpty( embeddedSource.getName() ) ) {
1887+
if ( StringHelper.isNotEmpty( embeddedSource.getXmlNodeName() ) ) {
18881888
DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfDomEntityModeSupport();
18891889
}
18901890

@@ -2437,7 +2437,7 @@ private void bindProperty(
24372437
Property property) {
24382438
property.setName( propertySource.getName() );
24392439

2440-
if ( StringHelper.isNotEmpty( propertySource.getName() ) ) {
2440+
if ( StringHelper.isNotEmpty( propertySource.getXmlNodeName() ) ) {
24412441
DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfDomEntityModeSupport();
24422442
}
24432443

hibernate-core/src/main/java/org/hibernate/internal/log/DeprecationLogger.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.hibernate.internal.log;
88

9+
import org.jboss.logging.BasicLogger;
910
import org.jboss.logging.Logger;
1011
import org.jboss.logging.annotations.LogMessage;
1112
import org.jboss.logging.annotations.Message;
@@ -22,7 +23,7 @@
2223
*/
2324
@MessageLogger( projectCode = "HHH" )
2425
@ValidIdRange( min = 90000001, max = 90001000 )
25-
public interface DeprecationLogger {
26+
public interface DeprecationLogger extends BasicLogger {
2627
public static final DeprecationLogger DEPRECATION_LOGGER = Logger.getMessageLogger(
2728
DeprecationLogger.class,
2829
"org.hibernate.orm.deprecation"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.test.entitymode.dom4j;
8+
9+
/**
10+
* @author Carsten Hammer
11+
* @author Steve Ebersole
12+
*/
13+
public class Car {
14+
protected Long id;
15+
protected Long quantity;
16+
protected Component component;
17+
18+
public Long getId() {
19+
return this.id;
20+
}
21+
22+
public void setId(Long id) {
23+
this.id = id;
24+
}
25+
26+
public Long getQuantity() {
27+
return quantity;
28+
}
29+
30+
public void setQuantity(Long quantity) {
31+
this.quantity = quantity;
32+
}
33+
34+
public Component getComponent() {
35+
return component;
36+
}
37+
38+
public void setComponent(Component component) {
39+
this.component = component;
40+
}
41+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.test.entitymode.dom4j;
8+
9+
/**
10+
* @author Steve Ebersole
11+
*/
12+
public class Component {
13+
private String something;
14+
private String somethingElse;
15+
16+
public String getSomething() {
17+
return something;
18+
}
19+
20+
public void setSomething(String something) {
21+
this.something = something;
22+
}
23+
24+
public String getSomethingElse() {
25+
return somethingElse;
26+
}
27+
28+
public void setSomethingElse(String somethingElse) {
29+
this.somethingElse = somethingElse;
30+
}
31+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.test.entitymode.dom4j;
8+
9+
import org.hibernate.boot.MetadataSources;
10+
import org.hibernate.internal.log.DeprecationLogger;
11+
12+
import org.hibernate.testing.junit4.BaseUnitTestCase;
13+
import org.hibernate.testing.logger.LoggerInspectionRule;
14+
import org.junit.Rule;
15+
import org.junit.Test;
16+
17+
/**
18+
* Tests that {@code hbm.xml} mappings that do not specify dom4j entity-mode information
19+
* do not trigger deprecation logging
20+
*
21+
* @author Steve Ebersole
22+
*/
23+
public class DeprecationLoggingTest extends BaseUnitTestCase {
24+
@Rule
25+
public LoggerInspectionRule logInspection = new LoggerInspectionRule( DeprecationLogger.DEPRECATION_LOGGER );
26+
27+
@Test
28+
public void basicTest() {
29+
logInspection.registerListener( LogListenerImpl.INSTANCE );
30+
31+
new MetadataSources().addResource( "org/hibernate/test/entitymode/dom4j/Car.hbm.xml" )
32+
.buildMetadata();
33+
}
34+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.test.entitymode.dom4j;
8+
9+
import org.hibernate.testing.logger.LogListener;
10+
11+
import org.jboss.logging.Logger;
12+
13+
/**
14+
* @author Steve Ebersole
15+
*/
16+
public class LogListenerImpl implements LogListener {
17+
/**
18+
* Singleton access
19+
*/
20+
public static final LogListenerImpl INSTANCE = new LogListenerImpl();
21+
22+
@Override
23+
public void loggedEvent(Logger.Level level, String renderedMessage, Throwable thrown) {
24+
if ( renderedMessage != null && renderedMessage.startsWith( "HHH90000003: " ) ) {
25+
throw new AssertionError( "Deprecation message was triggered" );
26+
}
27+
}
28+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
~ Hibernate, Relational Persistence for Idiomatic Java
4+
~
5+
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
6+
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
7+
-->
8+
<hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping" package="org.hibernate.test.entitymode.dom4j">
9+
<class name="Car" table="Car">
10+
<cache usage="nonstrict-read-write" region="org.hibernate.test.entitymode.dom4j.Car"/>
11+
<id name="id" column="id" type="java.lang.Long">
12+
<generator class="native">
13+
<param name="sequence">cat_id_sequence</param>
14+
</generator>
15+
</id>
16+
<property name="quantity" type="java.lang.Long">
17+
<column name="quantity" />
18+
</property>
19+
<component name="component" class="Component">
20+
<property name="something"/>
21+
<property name="somethingElse"/>
22+
</component>
23+
</class>
24+
</hibernate-mapping>

hibernate-testing/src/main/java/org/hibernate/testing/logger/LogListener.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
import org.jboss.logging.Logger.Level;
1010

11-
interface LogListener {
12-
11+
public interface LogListener {
1312
void loggedEvent(Level level, String renderedMessage, Throwable thrown);
14-
1513
}

0 commit comments

Comments
 (0)