HHH-14880 orm.xml: Take into account <package> for <converter class="...">
This commit is contained in:
parent
5f6e53334c
commit
fc636995c3
|
@ -107,7 +107,7 @@ public class XMLContext implements Serializable {
|
||||||
entityMappingDefault.setAccess( entityMappings.getAccess() );
|
entityMappingDefault.setAccess( entityMappings.getAccess() );
|
||||||
defaultElements.add( entityMappings );
|
defaultElements.add( entityMappings );
|
||||||
|
|
||||||
setLocalAttributeConverterDefinitions( entityMappings.getConverter() );
|
setLocalAttributeConverterDefinitions( entityMappings.getConverter(), packageName );
|
||||||
|
|
||||||
addClass( entityMappings.getEntity(), packageName, entityMappingDefault, addedClasses );
|
addClass( entityMappings.getEntity(), packageName, entityMappingDefault, addedClasses );
|
||||||
|
|
||||||
|
@ -168,14 +168,14 @@ public class XMLContext implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void setLocalAttributeConverterDefinitions(List<JaxbConverter> converterElements) {
|
private void setLocalAttributeConverterDefinitions(List<JaxbConverter> converterElements, String packageName) {
|
||||||
for ( JaxbConverter converterElement : converterElements ) {
|
for ( JaxbConverter converterElement : converterElements ) {
|
||||||
final String className = converterElement.getClazz();
|
final String className = converterElement.getClazz();
|
||||||
final boolean autoApply = Boolean.TRUE.equals( converterElement.isAutoApply() );
|
final boolean autoApply = Boolean.TRUE.equals( converterElement.isAutoApply() );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final Class<? extends AttributeConverter> attributeConverterClass = classLoaderAccess.classForName(
|
final Class<? extends AttributeConverter> attributeConverterClass = classLoaderAccess.classForName(
|
||||||
className
|
buildSafeClassName( className, packageName )
|
||||||
);
|
);
|
||||||
attributeConverterInfoList.add(
|
attributeConverterInfoList.add(
|
||||||
new AttributeConverterDefinition( attributeConverterClass.newInstance(), autoApply )
|
new AttributeConverterDefinition( attributeConverterClass.newInstance(), autoApply )
|
||||||
|
|
|
@ -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
|
@Test
|
||||||
public void testBasicConverterDisableApplication() {
|
public void testBasicConverterDisableApplication() {
|
||||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue