ClassCastException in ParameterizedTypeImpl
ebu Sep 30, 2005 8:13 AMHi.
I got
java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl
at sun.reflect.annotation.AnnotationParser.toClass(AnnotationParser.java:360)
at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:353)
at sun.reflect.annotation.AnnotationParser.parseClassValue(AnnotationParser.java:335)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:264)
at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:206)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
at java.lang.reflect.Field.declaredAnnotations(Field.java:1002)
at java.lang.reflect.Field.getAnnotation(Field.java:989)
at java.lang.reflect.AccessibleObject.isAnnotationPresent(AccessibleObject.java:175)
at org.hibernate.cfg.AnnotationBinder.addAnnotatedElement(AnnotationBinder.java:831)
at org.hibernate.cfg.AnnotationBinder.addElementsOfAClass(AnnotationBinder.java:814)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:638)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:256)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:191)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:970)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:607)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:75)
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:473)
at org.hibernate.ejb.Ejb3Configuration.createContainerEntityManagerFactory(Ejb3Configuration.java:202)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:78)
at org.jboss.ejb3.Ejb3Deployment.initializeManagedEntityManagerFactory(Ejb3Deployment.java:512)
when trying to deploy the bean
package test.ejb3.beans; import java.io.Serializable; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import javax.persistence.AccessType; import javax.persistence.Entity; import javax.persistence.GeneratorType; import javax.persistence.Id; @Entity(access=AccessType.FIELD) public class Entity1<T extends Entity1> implements Serializable{ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Anno { Class<? extends Intf> value(); } @Anno(Inner.class) private String name; public interface Intf { } public class Inner implements Intf{ } public static void main(String[] args) throws SecurityException, NoSuchFieldException { Entity1.class.getDeclaredField("name").getAnnotation(Anno.class); System.out.println("Ok"); } private static final long serialVersionUID = -8975907644508940951L; @Id(generate = GeneratorType.AUTO) private int id; }
The exception disappears if type variable T is removed. Any ideas why this happens?
wbe, eugen.