HHH-14880 orm.xml: Take into account <package> for <converter class="...">

This commit is contained in:
Yoann Rodière 2021-10-14 14:31:41 +02:00
parent 5f6e53334c
commit fc636995c3
3 changed files with 47 additions and 3 deletions

View File

@ -107,7 +107,7 @@ public class XMLContext implements Serializable {
entityMappingDefault.setAccess( entityMappings.getAccess() );
defaultElements.add( entityMappings );
setLocalAttributeConverterDefinitions( entityMappings.getConverter() );
setLocalAttributeConverterDefinitions( entityMappings.getConverter(), packageName );
addClass( entityMappings.getEntity(), packageName, entityMappingDefault, addedClasses );
@ -168,14 +168,14 @@ public class XMLContext implements Serializable {
}
@SuppressWarnings("unchecked")
private void setLocalAttributeConverterDefinitions(List<JaxbConverter> converterElements) {
private void setLocalAttributeConverterDefinitions(List<JaxbConverter> converterElements, String packageName) {
for ( JaxbConverter converterElement : converterElements ) {
final String className = converterElement.getClazz();
final boolean autoApply = Boolean.TRUE.equals( converterElement.isAutoApply() );
try {
final Class<? extends AttributeConverter> attributeConverterClass = classLoaderAccess.classForName(
className
buildSafeClassName( className, packageName )
);
attributeConverterInfoList.add(
new AttributeConverterDefinition( attributeConverterClass.newInstance(), autoApply )

View File

@ -210,6 +210,37 @@ public class AttributeConverterTest extends BaseUnitTestCase {
}
}
@Test
@TestForIssue(jiraKey = "HHH-14881")
public void testBasicOrmXmlConverterWithOrmXmlPackage() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
.addAnnotatedClass( Tester.class )
.addURL( ConfigHelper.findAsResource( "org/hibernate/test/converter/package.xml" ) )
.getMetadataBuilder()
.build();
PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() );
Property nameProp = tester.getProperty( "name" );
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
Type type = nameValue.getType();
assertNotNull( type );
if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) {
fail( "AttributeConverter not applied" );
}
final AttributeConverterTypeAdapter basicType = assertTyping( AttributeConverterTypeAdapter.class, type );
assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() );
final SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor();
assertEquals( Dialect.getDialect().remapSqlTypeDescriptor(ClobTypeDescriptor.CLOB_BINDING).getSqlType(), sqlTypeDescriptor.getSqlType() );
}
finally {
StandardServiceRegistryBuilder.destroy( ssr );
}
}
@Test
public void testBasicConverterDisableApplication() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<entity-mappings xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"
version="2.1">
<package>org.hibernate.test.converter</package>
<converter class="StringClobConverter" auto-apply="true"/>
</entity-mappings>