From fc636995c3cf624d941549225c2accc35a93a34b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Thu, 14 Oct 2021 14:31:41 +0200 Subject: [PATCH] HHH-14880 orm.xml: Take into account for --- .../reflection/internal/XMLContext.java | 6 ++-- .../converter/AttributeConverterTest.java | 31 +++++++++++++++++++ .../org/hibernate/test/converter/package.xml | 13 ++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 hibernate-core/src/test/resources/org/hibernate/test/converter/package.xml diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/reflection/internal/XMLContext.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/reflection/internal/XMLContext.java index 32e5aac982..c949c2d09a 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/reflection/internal/XMLContext.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/reflection/internal/XMLContext.java @@ -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 converterElements) { + private void setLocalAttributeConverterDefinitions(List converterElements, String packageName) { for ( JaxbConverter converterElement : converterElements ) { final String className = converterElement.getClazz(); final boolean autoApply = Boolean.TRUE.equals( converterElement.isAutoApply() ); try { final Class attributeConverterClass = classLoaderAccess.classForName( - className + buildSafeClassName( className, packageName ) ); attributeConverterInfoList.add( new AttributeConverterDefinition( attributeConverterClass.newInstance(), autoApply ) diff --git a/hibernate-core/src/test/java/org/hibernate/test/converter/AttributeConverterTest.java b/hibernate-core/src/test/java/org/hibernate/test/converter/AttributeConverterTest.java index 2d71536d6e..0e726cc81c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/converter/AttributeConverterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/converter/AttributeConverterTest.java @@ -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(); diff --git a/hibernate-core/src/test/resources/org/hibernate/test/converter/package.xml b/hibernate-core/src/test/resources/org/hibernate/test/converter/package.xml new file mode 100644 index 0000000000..60a730d826 --- /dev/null +++ b/hibernate-core/src/test/resources/org/hibernate/test/converter/package.xml @@ -0,0 +1,13 @@ + + + + + org.hibernate.test.converter + +