diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/domain/Entity.java b/hibernate-core/src/main/java/org/hibernate/metamodel/domain/Entity.java index 2e2ba49fb8..106eb3010a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/domain/Entity.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/domain/Entity.java @@ -24,7 +24,9 @@ package org.hibernate.metamodel.domain; import org.hibernate.EntityMode; +import org.hibernate.MappingException; import org.hibernate.service.classloading.spi.ClassLoaderService; +import org.hibernate.tuple.entity.EntityTuplizer; /** * Models the notion of an entity @@ -65,10 +67,12 @@ public class Entity extends AbstractAttributeContainer { public EntityMode getEntityMode(); public String getTuplizerClassName(); + + public Class getTuplizerClass(); } public static class PojoEntitySpecifics implements EntityModeEntitySpecifics { - private String tuplizerClassName; + private JavaType tuplizerClass; private JavaType entityClass; private JavaType proxyInterface; @@ -78,11 +82,20 @@ public class Entity extends AbstractAttributeContainer { } public String getTuplizerClassName() { - return tuplizerClassName; + return tuplizerClass.getName(); } - public void setTuplizerClassName(String tuplizerClassName) { - this.tuplizerClassName = tuplizerClassName; + public void setTuplizerClassName(String tuplizerClassName, ClassLoaderService classLoaderService) { + this.tuplizerClass = new JavaType( tuplizerClassName, classLoaderService); + } + + @SuppressWarnings( {"unchecked"} ) + public Class getTuplizerClass() { + Class clazz = tuplizerClass.getClassReference(); + if ( ! EntityTuplizer.class.isAssignableFrom( clazz ) ) { + throw new MappingException( "Class does not implement EntityTuplizer" ); + } + return ( Class ) clazz; } public String getClassName() { @@ -112,7 +125,7 @@ public class Entity extends AbstractAttributeContainer { public static class MapEntitySpecifics implements EntityModeEntitySpecifics { - private String tuplizerClassName; + private JavaType tuplizerClass; @Override public EntityMode getEntityMode() { @@ -120,12 +133,22 @@ public class Entity extends AbstractAttributeContainer { } public String getTuplizerClassName() { - return tuplizerClassName; + return tuplizerClass.getName(); } - public void setTuplizerClassName(String tuplizerClassName) { - this.tuplizerClassName = tuplizerClassName; + public void setTuplizerClassName(String tuplizerClassName, ClassLoaderService classLoaderService) { + this.tuplizerClass = new JavaType( tuplizerClassName, classLoaderService ); } + + @SuppressWarnings( {"unchecked"} ) + public Class getTuplizerClass() { + Class clazz = tuplizerClass.getClassReference(); + if ( ! EntityTuplizer.class.isAssignableFrom( clazz ) ) { + throw new MappingException( "Class does not implement EntityTuplizer" ); + } + return ( Class ) clazz; + } + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntityBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntityBinder.java index 5ca87a7e5a..a05b55c9b8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntityBinder.java @@ -170,15 +170,17 @@ abstract class AbstractEntityBinder { XMLTuplizerElement tuplizer = locateTuplizerDefinition( entityClazz, EntityMode.POJO ); if ( tuplizer != null ) { - entityBinding.getEntity().getPojoEntitySpecifics().setTuplizerClassName( tuplizer.getClazz() ); + entityBinding.getEntity().getPojoEntitySpecifics().setTuplizerClassName( tuplizer.getClazz(), classLoaderService ); } } private void bindMapRepresentation(XMLHibernateMapping.XMLClass entityClazz, EntityBinding entityBinding) { XMLTuplizerElement tuplizer = locateTuplizerDefinition( entityClazz, EntityMode.MAP ); + final ClassLoaderService classLoaderService = + bindingContext.getServiceRegistry().getService( ClassLoaderService.class ); if ( tuplizer != null ) { - entityBinding.getEntity().getMapEntitySpecifics().setTuplizerClassName( tuplizer.getClazz() ); + entityBinding.getEntity().getMapEntitySpecifics().setTuplizerClassName( tuplizer.getClazz(), classLoaderService ); } }