[hibernate-commits] Hibernate SVN: r19718 - in core/branches/Branch_3_5/entitymanager/src: test/java/org/hibernate/ejb/test and 1 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Fri Jun 11 16:06:12 EDT 2010
Author: steve.ebersole at jboss.com
Date: 2010-06-11 16:06:11 -0400 (Fri, 11 Jun 2010)
New Revision: 19718
Added:
core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/WithGenericCollection.java
Modified:
core/branches/Branch_3_5/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/test/TestCase.java
core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
Log:
HHH-5098 - AssertionFailure thrown when collection contains a parameterized type
Modified: core/branches/Branch_3_5/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
===================================================================
--- core/branches/Branch_3_5/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java 2010-06-11 18:13:13 UTC (rev 19717)
+++ core/branches/Branch_3_5/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java 2010-06-11 20:06:11 UTC (rev 19718)
@@ -618,6 +618,14 @@
return member;
}
+ public String getMemberDescription() {
+ return determineMemberDescription( getMember() );
+ }
+
+ public String determineMemberDescription(Member member) {
+ return member.getDeclaringClass().getName() + '#' + member.getName();
+ }
+
public Class<Y> getJavaType() {
return javaType;
}
@@ -823,20 +831,23 @@
}
private Class<?> getClassFromGenericArgument(java.lang.reflect.Type type) {
- Class<?> javaType;
- Object unsafeElementType = type;
- if ( unsafeElementType instanceof Class ) {
- javaType = (Class) unsafeElementType;
+ if ( type instanceof Class ) {
+ return (Class) type;
}
- else if ( unsafeElementType instanceof TypeVariable ) {
- final java.lang.reflect.Type upperBound = ( ( TypeVariable ) unsafeElementType ).getBounds()[0];
- javaType = getClassFromGenericArgument( upperBound );
+ else if ( type instanceof TypeVariable ) {
+ final java.lang.reflect.Type upperBound = ( ( TypeVariable ) type ).getBounds()[0];
+ return getClassFromGenericArgument( upperBound );
}
+ else if ( type instanceof ParameterizedType ) {
+ final java.lang.reflect.Type rawType = ( (ParameterizedType) type ).getRawType();
+ return getClassFromGenericArgument( rawType );
+ }
else {
- throw new AssertionFailure("Fail to process type argument in a generic declaration. Type: "
- + type.getClass() );
+ throw new AssertionFailure(
+ "Fail to process type argument in a generic declaration. Member : " + getMemberDescription()
+ + " Type: " + type.getClass()
+ );
}
- return javaType;
}
public ValueContext getElementValueContext() {
Modified: core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/test/TestCase.java
===================================================================
--- core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/test/TestCase.java 2010-06-11 18:13:13 UTC (rev 19717)
+++ core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/test/TestCase.java 2010-06-11 20:06:11 UTC (rev 19718)
@@ -1,4 +1,3 @@
-// $Id$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
@@ -36,8 +35,8 @@
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment;
@@ -53,9 +52,8 @@
* @author Hardy Ferentschik
*/
public abstract class TestCase extends HibernateTestCase {
+ private static final Logger log = LoggerFactory.getLogger( TestCase.class );
- private static final Log log = LogFactory.getLog( TestCase.class );
-
protected static EntityManagerFactory factory;
private EntityManager em;
private ArrayList isolatedEms = new ArrayList();
Modified: core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
===================================================================
--- core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java 2010-06-11 18:13:13 UTC (rev 19717)
+++ core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java 2010-06-11 20:06:11 UTC (rev 19718)
@@ -38,7 +38,10 @@
import javax.persistence.metamodel.MappedSuperclassType;
import javax.persistence.metamodel.IdentifiableType;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.ejb.metamodel.MetamodelImpl;
import org.hibernate.ejb.test.TestCase;
+import org.hibernate.engine.SessionFactoryImplementor;
/**
* @author Emmanuel Bernard
@@ -52,6 +55,16 @@
assertNotNull( entityType );
}
+ @SuppressWarnings({ "unchecked" })
+ public void testBuildingMetamodelWithParameterizedCollection() {
+ AnnotationConfiguration cfg = new AnnotationConfiguration( );
+ configure( cfg );
+ cfg.addAnnotatedClass( WithGenericCollection.class );
+ cfg.buildMappings();
+ SessionFactoryImplementor sfi = (SessionFactoryImplementor) cfg.buildSessionFactory();
+ MetamodelImpl.buildMetamodel( cfg.getClassMappings(), sfi );
+ }
+
public void testLogicalManyToOne() throws Exception {
final EntityType<JoinedManyToOneOwner> entityType = factory.getMetamodel().entity( JoinedManyToOneOwner.class );
final SingularAttribute attr = entityType.getDeclaredSingularAttribute( "house" );
@@ -98,7 +111,7 @@
assertNotNull( houseId );
assertTrue( houseId.isId() );
assertEquals( Attribute.PersistentAttributeType.EMBEDDED, houseId.getPersistentAttributeType() );
-
+
final EntityType<Person> personType = factory.getMetamodel().entity( Person.class );
assertFalse( personType.hasSingleIdAttribute() );
final Set<SingularAttribute<? super Person,?>> ids = personType.getIdClassAttributes();
@@ -218,7 +231,7 @@
assertTrue( cat.hasVersionAttribute() );
assertEquals( "version", cat.getVersion(Long.class).getName() );
- verifyDeclaredVersiobnNotPresent( cat );
+ verifyDeclaredVersionNotPresent( cat );
verifyDeclaredIdNotPresentAndIdPresent(cat);
assertEquals( Type.PersistenceType.MAPPED_SUPERCLASS, cat.getSupertype().getPersistenceType() );
@@ -229,7 +242,7 @@
assertTrue( cattish.hasVersionAttribute() );
assertEquals( "version", cattish.getVersion(Long.class).getName() );
- verifyDeclaredVersiobnNotPresent( cattish );
+ verifyDeclaredVersionNotPresent( cattish );
verifyDeclaredIdNotPresentAndIdPresent(cattish);
assertEquals( Type.PersistenceType.ENTITY, cattish.getSupertype().getPersistenceType() );
@@ -240,7 +253,7 @@
assertTrue( feline.hasVersionAttribute() );
assertEquals( "version", feline.getVersion(Long.class).getName() );
- verifyDeclaredVersiobnNotPresent( feline );
+ verifyDeclaredVersionNotPresent( feline );
verifyDeclaredIdNotPresentAndIdPresent(feline);
assertEquals( Type.PersistenceType.MAPPED_SUPERCLASS, feline.getSupertype().getPersistenceType() );
@@ -251,7 +264,7 @@
assertTrue( animal.hasVersionAttribute() );
assertEquals( "version", animal.getVersion(Long.class).getName() );
- verifyDeclaredVersiobnNotPresent( animal );
+ verifyDeclaredVersionNotPresent( animal );
assertEquals( "id", animal.getId(Long.class).getName() );
final SingularAttribute<Animal, Long> id = animal.getDeclaredId( Long.class );
assertEquals( "id", id.getName() );
@@ -318,7 +331,7 @@
}
}
- private void verifyDeclaredVersiobnNotPresent(IdentifiableType<?> type) {
+ private void verifyDeclaredVersionNotPresent(IdentifiableType<?> type) {
try {
type.getDeclaredVersion(Long.class);
fail("Should not have a declared version");
Added: core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/WithGenericCollection.java
===================================================================
--- core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/WithGenericCollection.java (rev 0)
+++ core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/WithGenericCollection.java 2010-06-11 20:06:11 UTC (rev 19718)
@@ -0,0 +1,86 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.ejb.test.metadata;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.ArrayList;
+import javax.persistence.*;
+
+/**
+* This class has a List of mapped entity objects that are themselves parameterized.
+* This class was added for JIRA issue #HHH-
+*
+* @author Kahli Burke
+*/
+ at Entity
+ at Table(name = "WITH_GENERIC_COLLECTION")
+public class WithGenericCollection<T> implements java.io.Serializable {
+ @Id
+ @Column(name = "ID")
+ private String id;
+
+ @Basic(optional=false)
+ private double d;
+
+ @ManyToOne(optional=false)
+ @JoinColumn(name="PARENT_ID", insertable=false, updatable=false)
+ private WithGenericCollection<? extends Object> parent = null;
+
+ @OneToMany(cascade = CascadeType.ALL)
+ @JoinColumn(name="PARENT_ID")
+ private List<WithGenericCollection<? extends Object>> children = new ArrayList<WithGenericCollection<? extends Object>>();
+
+ public WithGenericCollection() {
+ }
+
+ //====================================================================
+ // getters and setters for State fields
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setD(double d) {
+ this.d = d;
+ }
+
+ public double getD() {
+ return d;
+ }
+
+ public List<WithGenericCollection<? extends Object>> getChildren() {
+ return children;
+ }
+
+ public void setChildren(List<WithGenericCollection<? extends Object>> children) {
+ this.children = children;
+ }
+
+
+}
More information about the hibernate-commits
mailing list