
|
If you were logged in you would be able to see more operations.
|
|
|
|
Environment:
|
windowsXP jdk1.6.0_07 Tomcat6.0.16 spring2.5.4 hibernate3.2.6
|
|
Issue Links:
|
Duplicate
|
|
This issue duplicates:
|
|
GDS-173
throws NoConverterFoundException when the enity use generic type
|
|
|
|
|
|
|
|
|
the code in Converter.java:
if (targetType instanceof TypeVariable) {
TypeVariable<?> typeVariable = (TypeVariable<?>)targetType;
if (typeVariable.getGenericDeclaration() instanceof Type)
targetType = (Type)typeVariable.getGenericDeclaration();
}
the problem is "typeVariable.getGenericDeclaration()", this method returns the GenericDeclaration object representing the generic declaration declared this type variable. it's not true.
I think use "typeVariable.getBounds()" ,it's returns an array of Types representing the upper bound(s) of this type variable.
example entity code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Application<T extends ApplicationMeta> extends
AbstractEntity {
private static final long serialVersionUID = -5063254461237352117L;
private T applicationMeta;
@ManyToOne(fetch = FetchType.LAZY, targetEntity = ApplicationMeta.class)
@JoinColumn(name = "META_ID", nullable = false)
public T getApplicationMeta() {
return applicationMeta;
}
public void setApplicationMeta(T meta) {
this.applicationMeta = meta;
}
}
getGenericDeclaration returns Application,getBounds returns [ApplicationMeta],ApplicationMeta is expected.
|
|
Description
|
the code in Converter.java:
if (targetType instanceof TypeVariable) {
TypeVariable<?> typeVariable = (TypeVariable<?>)targetType;
if (typeVariable.getGenericDeclaration() instanceof Type)
targetType = (Type)typeVariable.getGenericDeclaration();
}
the problem is "typeVariable.getGenericDeclaration()", this method returns the GenericDeclaration object representing the generic declaration declared this type variable. it's not true.
I think use "typeVariable.getBounds()" ,it's returns an array of Types representing the upper bound(s) of this type variable.
example entity code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Application<T extends ApplicationMeta> extends
AbstractEntity {
private static final long serialVersionUID = -5063254461237352117L;
private T applicationMeta;
@ManyToOne(fetch = FetchType.LAZY, targetEntity = ApplicationMeta.class)
@JoinColumn(name = "META_ID", nullable = false)
public T getApplicationMeta() {
return applicationMeta;
}
public void setApplicationMeta(T meta) {
this.applicationMeta = meta;
}
}
getGenericDeclaration returns Application,getBounds returns [ApplicationMeta],ApplicationMeta is expected.
|
Show » |
Sort Order:
|
ClassUtil.java:
public static Type getBoundType(TypeVariable<?> typeVariable) {
Type[] ubs = typeVariable.getBounds();
if (ubs.length > 0)
return ubs[0];
// should never happen...
if (typeVariable.getGenericDeclaration() instanceof Type)
return (Type)typeVariable.getGenericDeclaration();
return typeVariable;
}
This method is used Converter.java & Converters.java.
Thanks!
Franck.