Skip to content

Commit fc63699

Browse files
committed
HHH-14880 orm.xml: Take into account <package> for <converter class="...">
1 parent 5f6e533 commit fc63699

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

hibernate-core/src/main/java/org/hibernate/cfg/annotations/reflection/internal/XMLContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public List<String> addDocument(JaxbEntityMappings entityMappings) {
107107
entityMappingDefault.setAccess( entityMappings.getAccess() );
108108
defaultElements.add( entityMappings );
109109

110-
setLocalAttributeConverterDefinitions( entityMappings.getConverter() );
110+
setLocalAttributeConverterDefinitions( entityMappings.getConverter(), packageName );
111111

112112
addClass( entityMappings.getEntity(), packageName, entityMappingDefault, addedClasses );
113113

@@ -168,14 +168,14 @@ private List<String> addEntityListenerClasses(JaxbEntityListeners listeners, Str
168168
}
169169

170170
@SuppressWarnings("unchecked")
171-
private void setLocalAttributeConverterDefinitions(List<JaxbConverter> converterElements) {
171+
private void setLocalAttributeConverterDefinitions(List<JaxbConverter> converterElements, String packageName) {
172172
for ( JaxbConverter converterElement : converterElements ) {
173173
final String className = converterElement.getClazz();
174174
final boolean autoApply = Boolean.TRUE.equals( converterElement.isAutoApply() );
175175

176176
try {
177177
final Class<? extends AttributeConverter> attributeConverterClass = classLoaderAccess.classForName(
178-
className
178+
buildSafeClassName( className, packageName )
179179
);
180180
attributeConverterInfoList.add(
181181
new AttributeConverterDefinition( attributeConverterClass.newInstance(), autoApply )

hibernate-core/src/test/java/org/hibernate/test/converter/AttributeConverterTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,37 @@ public void testBasicOrmXmlConverterApplication() {
210210
}
211211
}
212212

213+
@Test
214+
@TestForIssue(jiraKey = "HHH-14881")
215+
public void testBasicOrmXmlConverterWithOrmXmlPackage() {
216+
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
217+
218+
try {
219+
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
220+
.addAnnotatedClass( Tester.class )
221+
.addURL( ConfigHelper.findAsResource( "org/hibernate/test/converter/package.xml" ) )
222+
.getMetadataBuilder()
223+
.build();
224+
225+
PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() );
226+
Property nameProp = tester.getProperty( "name" );
227+
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
228+
Type type = nameValue.getType();
229+
assertNotNull( type );
230+
if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) {
231+
fail( "AttributeConverter not applied" );
232+
}
233+
final AttributeConverterTypeAdapter basicType = assertTyping( AttributeConverterTypeAdapter.class, type );
234+
assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() );
235+
final SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor();
236+
assertEquals( Dialect.getDialect().remapSqlTypeDescriptor(ClobTypeDescriptor.CLOB_BINDING).getSqlType(), sqlTypeDescriptor.getSqlType() );
237+
}
238+
finally {
239+
StandardServiceRegistryBuilder.destroy( ssr );
240+
}
241+
}
242+
243+
213244
@Test
214245
public void testBasicConverterDisableApplication() {
215246
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
~ Hibernate, Relational Persistence for Idiomatic Java
5+
~
6+
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
7+
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
8+
-->
9+
<entity-mappings xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"
10+
version="2.1">
11+
<package>org.hibernate.test.converter</package>
12+
<converter class="StringClobConverter" auto-apply="true"/>
13+
</entity-mappings>

0 commit comments

Comments
 (0)