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


i new in java reflection.

i checked lot of forums, haven't found working solution.

the error:

caused by: java.lang.classcastexception: java.lang.class cannot cast java.lang.reflect.parameterizedtype 

comes when trying object db:

        new unit().getby(3l); 

the method declaration

@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 extension

@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 class:

@entity @table(name="common__unit") public class unit extends genericdictionary<unit> {     @manytoone(fetch=fetchtype.lazy)     @joincolumn(name="parent_id")     public unit parent; } 

and method call in controller:

new unit().getby(3l); 

it quite strange, cause have other entity can use method without runtime error this. here entity:

@entity @table(name="common__clinic") public class clinic extends genericdictionary<clinic> {     @manytomany(cascade = cascadetype.persist)     public list<unit> unit; 

and method call in other controller:

    clinic clinic = new clinic().getby(3l); 

this code works. dont see differences between models , controllers.

can 1 me pointing mistakes here?

---------------------------------------- edit --------------------------------------

full stack trace

[error] play - cannot invoke action, got error: javax.persistence.persistenceexception: org.hibernate.hibernateexception: javassist enhancement failed: models.unit [error] application -   ! @6kb72hhpo - internal server error, (post) [/supraadmin/oddzialy/zapisz] ->  play.api.application$$anon$1: execution exception[[persistenceexception: org.hibernate.hibernateexception: javassist enhancement failed: models.unit]]         @ play.api.application$class.handleerror(application.scala:293) ~[play_2.10-2.2.4.jar:2.2.4]         @ play.api.defaultapplication.handleerror(application.scala:399) [play_2.10-2.2.4.jar:2.2.4]         @ play.core.server.netty.playdefaultupstreamhandler$$anonfun$3$$anonfun$applyorelse$3.apply(playdefaultupstreamhandler.scala:264) [play_2.10-2.2.4.jar:2.2.4]         @ play.core.server.netty.playdefaultupstreamhandler$$anonfun$3$$anonfun$applyorelse$3.apply(playdefaultupstreamhandler.scala:264) [play_2.10-2.2.4.jar:2.2.4]         @ scala.option.map(option.scala:145) [scala-library.jar:na]         @ 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         @ org.hibernate.ejb.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1387) ~[hibernate-entitymanager-4.2.0.cr1.jar:4.2.0.cr1]         @ org.hibernate.ejb.abstractentitymanagerimpl.find(abstractentitymanagerimpl.java:838) ~[hibernate-entitymanager-4.2.0.cr1.jar:4.2.0.cr1]         @ org.hibernate.ejb.abstractentitymanagerimpl.find(abstractentitymanagerimpl.java:781) ~[hibernate-entitymanager-4.2.0.cr1.jar:4.2.0.cr1]         @ models.generic.getby(generic.java:62) ~[na:na]         @ controllers.admin.cms.unitssubmit(cms.java:477) ~[na:na]         @ 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         @ org.hibernate.proxy.pojo.javassist.javassistlazyinitializer.getproxy(javassistlazyinitializer.java:143) ~[hibernate-core-4.2.0.cr1.jar:4.2.0.cr1]         @ org.hibernate.proxy.pojo.javassist.javassistproxyfactory.getproxy(javassistproxyfactory.java:73) ~[hibernate-core-4.2.0.cr1.jar:4.2.0.cr1]         @ org.hibernate.tuple.entity.abstractentitytuplizer.createproxy(abstractentitytuplizer.java:758) ~[hibernate-core-4.2.0.cr1.jar:4.2.0.cr1]         @ org.hibernate.persister.entity.abstractentitypersister.createproxy(abstractentitypersister.java:4396) ~[hibernate-core-4.2.0.cr1.jar:4.2.0.cr1]         @ org.hibernate.event.internal.defaultloadeventlistener.createproxyifnecessary(defaultloadeventlistener.java:332) ~[hibernate-core-4.2.0.cr1.jar:4.2.0.cr1]         @ 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 cast java.lang.reflect.parameterizedtype         @ models.generic.<init>(generic.java:40) ~[na:na]         @ models.genericdictionary.<init>(genericdictionary.java:13) ~[na:na]         @ models.unit.<init>(unit.java:30) ~[na:na]         @ models.unit_$$_jvst57e_b5.<init>(unit_$$_jvst57e_b5.java) ~[na:na]         @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) ~[na:1.7.0_65]         @ 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 

the getgenericsuperclass approach doesn't work when using complex type hierarchy. instead might try using typetools:

generic() {     entityclass = (class<t>)typeresolver.resolverawargument(generic.class, getclass()); } 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -