Verursacht durch: java.lang.Classcastexception-Fehler: java.lang.Class kann nicht gewirkt werden, um java.lang.reflektieren.ParameterizedType

Ich bin neu in der Java-Reflection.

Ich überprüfte eine Menge Foren, aber ich habe keine funktionierende Lösung gefunden.

Den Fehler:

Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType

kommt, wenn ich versuche zu bekommen-Objekt aus db:

        new Unit().getBy(3L);

der Deklaration der Methode

@MappedSuperclass
public abstract class Generic<T extends Generic> {
    @Transient
    public Class<T> entityClass;
    Generic() {
        entityClass = ((Class) ((Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]));
    }
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    public Long id;

    public T getBy(Long id) {
        return JPA.em().find(entityClass, id);
    }

second-level-Erweiterung

@MappedSuperclass
public abstract class GenericDictionary<T extends Generic<T>> extends Generic<T> {

    @Required
    public String name;
    @Required
    public boolean active = true;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean getActive() {
        return active;
    }

    public void setActive(boolean stat) {
        this.active = stat;
    }

Entity-Klasse:

@Entity
@Table(name="common__Unit")
public class Unit extends GenericDictionary<Unit> {
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="parent_id")
    public Unit parent;
}

Methode und call-in-controller:

new Unit().getBy(3L);

Es ist ziemlich seltsam, denn ich habe andere Person, wo ich diese Methode verwenden können, ohne irgendwelche runtime-Fehlermeldung. Hier ist die entity:

@Entity
@Table(name="common__Clinic")
public class Clinic extends GenericDictionary<Clinic> {
    @ManyToMany(cascade = CascadeType.PERSIST)
    public List<Unit> unit;

Und aufrufen der Methode, in der andere controller:

    Clinic clinic = new Clinic().getBy(3L);

Dieser code funktioniert.
Ich dont sehen irgendwelche Unterschiede zwischen Modellen und Controllern.

Kann einer helfen, mir zeigen, meine Fehler hier?

---------------------------------------- BEARBEITEN --------------------------------------

volle stack-trace

[error] play - Cannot invoke the action, eventually got an error: javax.persistence.PersistenceException: org.hibernate.HibernateException: Javassist Enhancement failed: models.Unit
[error] application - 
! @6kb72hhpo - Internal server error, for (POST) [/SupraADMIN/oddzialy/zapisz] ->
play.api.Application$$anon$1: Execution exception[[PersistenceException: org.hibernate.HibernateException: Javassist Enhancement failed: models.Unit]]
at play.api.Application$class.handleError(Application.scala:293) ~[play_2.10-2.2.4.jar:2.2.4]
at play.api.DefaultApplication.handleError(Application.scala:399) [play_2.10-2.2.4.jar:2.2.4]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:264) [play_2.10-2.2.4.jar:2.2.4]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:264) [play_2.10-2.2.4.jar:2.2.4]
at scala.Option.map(Option.scala:145) [scala-library.jar:na]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3.applyOrElse(PlayDefaultUpstreamHandler.scala:264) [play_2.10-2.2.4.jar:2.2.4]
Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateException: Javassist Enhancement failed: models.Unit
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387) ~[hibernate-entitymanager-4.2.0.CR1.jar:4.2.0.CR1]
at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:838) ~[hibernate-entitymanager-4.2.0.CR1.jar:4.2.0.CR1]
at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:781) ~[hibernate-entitymanager-4.2.0.CR1.jar:4.2.0.CR1]
at models.Generic.getBy(Generic.java:62) ~[na:na]
at controllers.admin.CMS.UnitsSubmit(CMS.java:477) ~[na:na]
at admin.Routes$$anonfun$routes$1$$anonfun$applyOrElse$13$$anonfun$apply$13.apply(routes_routing.scala:317) ~[na:na]
Caused by: org.hibernate.HibernateException: Javassist Enhancement failed: models.Unit
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:143) ~[hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:73) ~[hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:758) ~[hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:4396) ~[hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
at org.hibernate.event.internal.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:332) ~[hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:258) ~[hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
at models.Generic.<init>(Generic.java:40) ~[na:na]
at models.GenericDictionary.<init>(GenericDictionary.java:13) ~[na:na]
at models.Unit.<init>(Unit.java:30) ~[na:na]
at models.Unit_$$_jvst57e_b5.<init>(Unit_$$_jvst57e_b5.java) ~[na:na]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.7.0_65]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.7.0_65]
[error] application - REGUEST: POST /SupraADMIN/oddzialy/zapisz GENERATED ERROR: @6kb72hhpo: Execution exception in /home/user/Aplikacje/Eclipse/SVP/modules/common/app/models/Generic.java:62
  • könntest du poste den vollständigen stack-trace?
  • Ok hab ich gemacht. Stack trace Hinzugefügt
InformationsquelleAutor masterdany88 | 2014-11-27
Schreibe einen Kommentar