java - Discriminator , WrongClassException JPA with Hibernate backend -
i have requirement have abstract superclass.
i have 6 subclasses abstract superclass.
i mapped them single_table inheritance strategy in jpa.
in pojo have 1 many relationship these 1+6 classes.
@onetomany(mappedby = "msearchpreference", cascade = cascadetype.all) private set<searchcriteria> msearchcriteria;
here "searchcriteria" abstract class.
@entity @table(name = "srch_crtr_t", schema = "lpew") @inheritance(strategy=inheritancetype.single_table) @discriminatorcolumn(name = "srch_discriminator_cde", discriminatortype = discriminatortype.string) @org.hibernate.annotations.forcediscriminator public abstract class searchcriteria extends basedbobject implements comparable<searchcriteria>
and has 6 concrete subclasses classes
@entity @discriminatorvalue("date") @inheritance(strategy=inheritancetype.single_table) public class searchcriteriadaterange extends searchcriteria
i can insert values table, when retrieving error:
caused by: org.hibernate.wrongclassexception: object id: 261 not of specified subclass: com.lmig.lit.lpew.model.criteria.searchcriteria (discriminator: date ) @ org.hibernate.loader.loader.getinstanceclass(loader.java:1453) @ org.hibernate.loader.loader.instancenotyetloaded(loader.java:1284) @ org.hibernate.loader.loader.getrow(loader.java:1206) @ org.hibernate.loader.loader.getrowfromresultset(loader.java:580) @ org.hibernate.loader.l 10:57:44,786 info [stdout] oader.doquery(loader.java:701) @ org.hibernate.loader.loader.doqueryandinitializenonlazycollections(loader.java:236) @ org.hibernate.loader.loader.loadcollection(loader.java:1994) @ org.hibernate.loader.collection.batchingcollectioninitializer.initialize(batchingcollectioninitializer.java:52) @ org.hibernate.persister.collection.abstractcollectionpersister.initialize(abstractcollectionpersister.java:565) @ org.hibernate.event.def.defaultinitializecollectioneventlistener.oninitializecollection(defaultinitializecollectioneventlistener.java:63) @ org.hibernate.impl.sessionimpl.initializecollection(sessionimpl.java:1716) @ org.hibernate.collection.abstractpersistentcollection.initialize(abstractpersistentcollection.java:344) @ org.hibernate.collection.abstractpersistentcollection.read(abstractpersistentcollection.java:86) @ org.hibernate.collection.abstractpersistentcollection.readelementexistence(abstractpersistentcollection.java:142) @ org.hibernate.collection.persistentset.add(persistentset.java:187) @ com.lmig.lit.lpew.model.homescreen.homescreenpreference.addsearchcriteriabytype(homescreenpreference.java:132) @ com.lmig.lit.lpew.model.homescreen.homescreenpreference.addsearchcriteriabytype(homescreenpreference.java:147) @ com.lmig.lit.lpew.service.lpewuserserviceimpl.initializehomescreenpreferences(lpewuserserviceimpl.java:135) @ com.lmig.lit.lpew.service.lpewuserserviceimpl.finduserandinitialize(lpewuserserviceimpl.java:103) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.springframework.aop.support.aoputils.invokejoinpointusingreflection(aoputils.java:307) @ org.springframework.aop.framework.reflectivemethodinvocation.invokejoinpoint(reflectivemethodinvocation.java:182) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:149) @ org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor.java:106) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:171) @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:204) @ $proxy122.finduserandinitialize(unknown source) @ com.lmig.lit.lpew.jsf.beans.usersession.getlpewuser(usersession.java:989) @ com.lmig.lit.lpew.jsf.beans.requestforservicebean.getallrequests(requestforservicebean.java:263) @ com.lmig.lit.lpew.jsf.beans.requestforservicebean.getallnewrequests(requestforservicebean.java:382) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ javax.el.beanelresolver.getvalue(beanelresolver.java:62) @ javax.el.compositeelresolver.getvalue(compositeelresolver.java:53) @ com.sun.faces.el.facescompositeelresolver.getvalue(facescompositeelresolver.java:64) @ org.apache.el.parser.astvalue.getvalue(astvalue.java:97) @ org.apache.el.valueexpressionimpl.getvalue(valueexpressionimpl.java:186)
does know solution?
you should use @org.hibernate.annotations.discriminatoroptions(force=true)
on root entity
Comments
Post a Comment