HHH-4834 Take into account that collections can be of raw type.

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18609 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Emmanuel Bernard 2010-01-22 19:21:33 +00:00
parent 9fc7794134
commit 690792493b
4 changed files with 154 additions and 6 deletions

View File

@ -734,12 +734,18 @@ public class AttributeFactory {
ParameterizedType signatureType = getSignatureType( member ); ParameterizedType signatureType = getSignatureType( member );
if ( keyPersistentAttributeType == null ) { if ( keyPersistentAttributeType == null ) {
elementJavaType = getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] ); elementJavaType = signatureType != null ?
getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] ) :
Object.class; //FIXME and honor targetEntity?
keyJavaType = null; keyJavaType = null;
} }
else { else {
keyJavaType = getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] ); keyJavaType = signatureType != null ?
elementJavaType = getClassFromGenericArgument( signatureType.getActualTypeArguments()[1] ); getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] ) :
Object.class; //FIXME and honor targetEntity?
elementJavaType = signatureType != null ?
getClassFromGenericArgument( signatureType.getActualTypeArguments()[1] ) :
Object.class; //FIXME and honor targetEntity?
} }
this.elementValueContext = new ValueContext() { this.elementValueContext = new ValueContext() {
@ -836,9 +842,12 @@ public class AttributeFactory {
} }
public static ParameterizedType getSignatureType(Member member) { public static ParameterizedType getSignatureType(Member member) {
return (ParameterizedType) ( Field.class.isInstance( member ) final java.lang.reflect.Type type = Field.class.isInstance( member )
? ( (Field) member ).getGenericType() ? ( ( Field ) member ).getGenericType()
: ( (Method) member ).getGenericReturnType()); : ( ( Method ) member ).getGenericReturnType();
//this is a raw type
if ( type instanceof Class ) return null;
return (ParameterizedType) type;
} }
public static PluralAttribute.CollectionType determineCollectionType(Class javaType) { public static PluralAttribute.CollectionType determineCollectionType(Class javaType) {

View File

@ -0,0 +1,61 @@
package org.hibernate.ejb.test.metadata;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
/**
* @author Emmanuel Bernard
*/
@Entity
public class DeskWithRawType implements java.io.Serializable {
@Id
protected String id;
@Basic
protected String name;
public DeskWithRawType() {
}
@ManyToMany(targetEntity = EmployeeWithRawType.class, cascade = CascadeType.ALL)
@JoinTable(name = "DESK_EMPL",
joinColumns =
@JoinColumn(
name = "DESK_FK", referencedColumnName = "ID"),
inverseJoinColumns =
@JoinColumn(
name = "EMPL_FK", referencedColumnName = "ID")
)
protected Collection employees = new java.util.ArrayList();
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Collection getEmployees() {
return employees;
}
public void setEmployees(Collection employees) {
this.employees = employees;
}
}

View File

@ -0,0 +1,52 @@
package org.hibernate.ejb.test.metadata;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
/**
* @author Emmanuel Bernard
*/
@Entity
public class EmployeeWithRawType implements java.io.Serializable {
@Id
protected String id;
@Basic
protected String name;
@ManyToMany(targetEntity = DeskWithRawType.class, mappedBy = "employees", cascade = CascadeType.ALL)
protected Collection desks = new java.util.ArrayList();
public EmployeeWithRawType() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Collection getDesks() {
return desks;
}
public void setDesks(Collection desks) {
this.desks = desks;
}
}

View File

@ -0,0 +1,26 @@
package org.hibernate.ejb.test.metadata;
import javax.persistence.EntityManagerFactory;
import org.hibernate.ejb.test.TestCase;
/**
* @author Emmanuel Bernard
*/
public class SecondMetadataTest extends TestCase {
public void testBaseOfService() throws Exception {
EntityManagerFactory emf = factory;
assertNotNull( emf.getMetamodel() );
assertNotNull( emf.getMetamodel().entity( DeskWithRawType.class ) );
assertNotNull( emf.getMetamodel().entity( EmployeeWithRawType.class ) );
}
@Override
public Class[] getAnnotatedClasses() {
return new Class[] {
DeskWithRawType.class,
EmployeeWithRawType.class
};
}
}