diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/HibernateTypeHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/HibernateTypeHelper.java index 9bfdbe441f..ef3f8221be 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/HibernateTypeHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/HibernateTypeHelper.java @@ -42,6 +42,7 @@ import org.hibernate.metamodel.reflite.spi.ClassDescriptor; import org.hibernate.metamodel.reflite.spi.FieldDescriptor; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.reflite.spi.MethodDescriptor; +import org.hibernate.metamodel.reflite.spi.PrimitiveTypeDescriptor; import org.hibernate.metamodel.source.spi.AttributeSource; import org.hibernate.metamodel.source.spi.BasicPluralAttributeElementSource; import org.hibernate.metamodel.source.spi.ComponentAttributeSource; @@ -522,12 +523,19 @@ class HibernateTypeHelper { return typeFactory().list( role, propertyRef ); } case ARRAY: { + // TODO: Move into a util? + final JavaTypeDescriptor descriptor = pluralAttributeSource.getElementTypeDescriptor(); + final Class clazz; + if (PrimitiveTypeDescriptor.class.isInstance( descriptor )) { + clazz = ( (PrimitiveTypeDescriptor) descriptor ).getClassType(); + } + else { + clazz = classLoaderService.classForName( descriptor.getName().toString() ); + } return typeFactory().array( role, propertyRef, - classLoaderService.classForName( - pluralAttributeSource.getElementTypeDescriptor().getName().toString() - ) + clazz ); } case MAP: { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/Primitives.java b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/Primitives.java index 6e63438e72..055ace361f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/Primitives.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/internal/Primitives.java @@ -219,15 +219,22 @@ public class Primitives { } private static class PrimitiveDescriptorImpl implements PrimitiveTypeDescriptor { + private final Class clazz; private final DotName name; private final int modifiers; private final PrimitiveGroup group; protected PrimitiveDescriptorImpl(Class clazz, PrimitiveGroup group) { + this.clazz = clazz; this.name = DotName.createSimple( clazz.getName() ); this.modifiers = clazz.getModifiers(); this.group = group; } + + @Override + public Class getClassType() { + return clazz; + } @Override public DotName getName() { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/PrimitiveTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/PrimitiveTypeDescriptor.java index 3905a812fe..b13e699f20 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/PrimitiveTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/reflite/spi/PrimitiveTypeDescriptor.java @@ -35,4 +35,12 @@ public interface PrimitiveTypeDescriptor extends JavaTypeDescriptor { * @return The descriptor for the wrapper "equivalent". */ public PrimitiveWrapperTypeDescriptor getWrapperTypeDescriptor(); + + /** + * Since primitives are ClassLoader safe, allow the Class itself to be available. Needed for ArrayType + * handling, etc. + * + * @return The primitive's Class + */ + public Class getClassType(); } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java index 6685b06f49..5a97b7f9d3 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java @@ -72,6 +72,8 @@ import org.hibernate.jdbc.Expectation; import org.hibernate.jdbc.Expectations; import org.hibernate.loader.collection.CollectionInitializer; import org.hibernate.metadata.CollectionMetadata; +import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; +import org.hibernate.metamodel.reflite.spi.PrimitiveTypeDescriptor; import org.hibernate.metamodel.spi.MetadataImplementor; import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.spi.binding.Cascadeable; @@ -560,10 +562,15 @@ public abstract class AbstractCollectionPersister isInverse = keyBinding.isInverse(); if ( isArray ) { - final ClassLoaderService cls = factory.getServiceRegistry().getService( ClassLoaderService.class ); - elementClass = cls.classForName( - collection.getAttribute().getElementType().getDescriptor().getName().toString() - ); + // TODO: Move into a util? + final JavaTypeDescriptor descriptor = collection.getAttribute().getElementType().getDescriptor(); + if (PrimitiveTypeDescriptor.class.isInstance( descriptor )) { + elementClass = ( (PrimitiveTypeDescriptor) descriptor ).getClassType(); + } + else { + final ClassLoaderService cls = factory.getServiceRegistry().getService( ClassLoaderService.class ); + elementClass = cls.classForName( descriptor.getName().toString() ); + } } else { // for non-arrays, we don't need to know the element class diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java index 1353fd3a52..069a0d8e1b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java @@ -23,6 +23,10 @@ */ package org.hibernate.test.annotations.collectionelement; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -34,23 +38,16 @@ import org.hibernate.Transaction; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; import org.hibernate.metamodel.spi.relational.TableSpecification; - -import org.hibernate.testing.FailureExpectedWithNewMetamodel; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.test.annotations.Country; import org.hibernate.test.util.SchemaUtil; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - /** * @author Emmanuel Bernard * @author Hardy Ferentschik */ @SuppressWarnings("unchecked") -@FailureExpectedWithNewMetamodel( jiraKey = "HHH-8962" ) public class CollectionElementTest extends BaseCoreFunctionalTestCase { @Test public void testSimpleElement() throws Exception {