mysql - Constructor queries on a non-persistent entity unexpectedly fail to supply a Boolean parameter as a constructor argument -
there 2 tables in mysql database
- user_table
- feedback
the relationship between them intuitive - 1 many user_table
feedback
.
i need fetch list of selected columns these tables are
- from feedback
- feedbackid (java.lang.long)
- feedbacktitle (java.lang.string)
- feedbackdescription (string, decorated
@lob
) - feedbackdate (org.joda.time.datetime)
- testimonial (java.lang.boolean)
- from user_table
- userid (java.lang.long)
- firstname (java.lang.string)
these many fields out of many others required executing query.
the criteria query follows.
criteriabuilder criteriabuilder=entitymanager.getcriteriabuilder(); criteriaquery<feedbackutils>criteriaquery = criteriabuilder.createquery(feedbackutils.class); metamodel metamodel = entitymanager.getmetamodel(); entitytype<feedback> entitytype = metamodel.entity(feedback.class); root<feedback> root = criteriaquery.from(entitytype); list<selection<?>>selections=new arraylist<selection<?>>(); selections.add(root.get(feedback_.feedbackid)); selections.add(root.get(feedback_.feedbacktitle)); selections.add(root.get(feedback_.feedbackdescription)); selections.add(root.get(feedback_.feedbackdate)); selections.add(root.get(feedback_.testimonial)); join<feedback, usertable> join = root.join(feedback_.userid, jointype.inner); selections.add(join.get(usertable_.userid)); selections.add(join.get(usertable_.firstname)); criteriaquery.select(criteriabuilder.construct(feedbackutils.class, selections.toarray(new selection[0]))); criteriaquery.orderby(criteriabuilder.desc(root.get(feedback_.feedbackid))); list<feedbackutils>list = entitymanager.createquery(criteriaquery).setfirstresult(first).setmaxresults(pagesize).getresultlist();
the feedbackutils
class follows.
import java.io.serializable; import org.joda.time.datetime; public final class feedbackutils implements serializable { private static final long serialversionuid = 1l; private long feedbackid; private string feedbacktitle; private string feedbackdescription; private datetime feedbackdate; private boolean testimonial; //this causes exception private long userid; private string firstname; public feedbackutils(long feedbackid, string feedbacktitle, string feedbackdescription, datetime feedbackdate, boolean testimonial, long userid, string firstname) { this.feedbackid = feedbackid; this.feedbacktitle = feedbacktitle; this.feedbackdescription = feedbackdescription; this.feedbackdate = feedbackdate; this.testimonial = testimonial; this.userid = userid; this.firstname = firstname; } //getters , setters. }
mapping of testimonial
property in feedback
entity follows.
@column(name = "testimonial") private boolean testimonial;
it type of tinyint(1)
in mysql.
the above query when attempted causes following exception thrown.
severe: error rendering view[/admin_side/feedback.xhtml] javax.ejb.ejbexception @ com.sun.ejb.containers.ejbcontainertransactionmanager.processsystemexception(ejbcontainertransactionmanager.java:748) @ com.sun.ejb.containers.ejbcontainertransactionmanager.completenewtx(ejbcontainertransactionmanager.java:698) @ com.sun.ejb.containers.ejbcontainertransactionmanager.postinvoketx(ejbcontainertransactionmanager.java:503) @ com.sun.ejb.containers.basecontainer.postinvoketx(basecontainer.java:4475) @ com.sun.ejb.containers.basecontainer.postinvoke(basecontainer.java:2009) @ com.sun.ejb.containers.basecontainer.postinvoke(basecontainer.java:1979) @ com.sun.ejb.containers.ejblocalobjectinvocationhandler.invoke(ejblocalobjectinvocationhandler.java:220) @ com.sun.ejb.containers.ejblocalobjectinvocationhandlerdelegate.invoke(ejblocalobjectinvocationhandlerdelegate.java:88) @ $proxy662.getlist(unknown source) @ admin.bean.feedbackmanagedbean.load(feedbackmanagedbean.java:174) @ org.primefaces.component.datatable.datatable.loadlazydata(datatable.java:815) @ org.primefaces.component.datatable.datatablerenderer.prerender(datatablerenderer.java:93) @ org.primefaces.component.datatable.datatablerenderer.encodeend(datatablerenderer.java:81) @ javax.faces.component.uicomponentbase.encodeend(uicomponentbase.java:919) @ org.primefaces.renderkit.corerenderer.renderchild(corerenderer.java:85) @ org.primefaces.renderkit.corerenderer.renderchildren(corerenderer.java:68) @ org.primefaces.component.panel.panelrenderer.encodecontent(panelrenderer.java:204) @ org.primefaces.component.panel.panelrenderer.encodemarkup(panelrenderer.java:121) @ org.primefaces.component.panel.panelrenderer.encodeend(panelrenderer.java:58) @ javax.faces.component.uicomponentbase.encodeend(uicomponentbase.java:919) @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1864) @ javax.faces.render.renderer.encodechildren(renderer.java:176) @ javax.faces.component.uicomponentbase.encodechildren(uicomponentbase.java:889) @ org.primefaces.renderkit.corerenderer.renderchild(corerenderer.java:81) @ org.primefaces.renderkit.corerenderer.renderchildren(corerenderer.java:68) @ org.primefaces.component.layout.layoutunitrenderer.encodeend(layoutunitrenderer.java:49) @ javax.faces.component.uicomponentbase.encodeend(uicomponentbase.java:919) @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1864) @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1860) @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1860) @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1860) @ com.sun.faces.application.view.faceletviewhandlingstrategy.renderview(faceletviewhandlingstrategy.java:461) @ com.sun.faces.application.view.multiviewhandler.renderview(multiviewhandler.java:133) @ javax.faces.application.viewhandlerwrapper.renderview(viewhandlerwrapper.java:337) @ javax.faces.application.viewhandlerwrapper.renderview(viewhandlerwrapper.java:337) @ com.sun.faces.lifecycle.renderresponsephase.execute(renderresponsephase.java:120) @ com.sun.faces.lifecycle.phase.dophase(phase.java:101) @ com.sun.faces.lifecycle.lifecycleimpl.render(lifecycleimpl.java:219) @ javax.faces.webapp.facesservlet.service(facesservlet.java:647) @ org.apache.catalina.core.standardwrapper.service(standardwrapper.java:1682) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:344) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:214) @ org.primefaces.webapp.filter.fileuploadfilter.dofilter(fileuploadfilter.java:70) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:256) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:214) @ filter.nocachefilter.dofilter(nocachefilter.java:28) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:256) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:214) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:316) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:160) @ org.apache.catalina.core.standardpipeline.doinvoke(standardpipeline.java:734) @ org.apache.catalina.core.standardpipeline.invoke(standardpipeline.java:673) @ com.sun.enterprise.web.webpipeline.invoke(webpipeline.java:99) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:174) @ org.apache.catalina.connector.coyoteadapter.doservice(coyoteadapter.java:357) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:260) @ com.sun.enterprise.v3.services.impl.containermapper.service(containermapper.java:188) @ org.glassfish.grizzly.http.server.httphandler.runservice(httphandler.java:191) @ org.glassfish.grizzly.http.server.httphandler.dohandle(httphandler.java:168) @ org.glassfish.grizzly.http.server.httpserverfilter.handleread(httpserverfilter.java:189) @ org.glassfish.grizzly.filterchain.executorresolver$9.execute(executorresolver.java:119) @ org.glassfish.grizzly.filterchain.defaultfilterchain.executefilter(defaultfilterchain.java:288) @ org.glassfish.grizzly.filterchain.defaultfilterchain.executechainpart(defaultfilterchain.java:206) @ org.glassfish.grizzly.filterchain.defaultfilterchain.execute(defaultfilterchain.java:136) @ org.glassfish.grizzly.filterchain.defaultfilterchain.process(defaultfilterchain.java:114) @ org.glassfish.grizzly.processorexecutor.execute(processorexecutor.java:77) @ org.glassfish.grizzly.nio.transport.tcpniotransport.fireioevent(tcpniotransport.java:838) @ org.glassfish.grizzly.strategies.abstractiostrategy.fireioevent(abstractiostrategy.java:113) @ org.glassfish.grizzly.strategies.workerthreadiostrategy.run0(workerthreadiostrategy.java:115) @ org.glassfish.grizzly.strategies.workerthreadiostrategy.access$100(workerthreadiostrategy.java:55) @ org.glassfish.grizzly.strategies.workerthreadiostrategy$workerthreadrunnable.run(workerthreadiostrategy.java:135) @ org.glassfish.grizzly.threadpool.abstractthreadpool$worker.dowork(abstractthreadpool.java:564) @ org.glassfish.grizzly.threadpool.abstractthreadpool$worker.run(abstractthreadpool.java:544) @ java.lang.thread.run(thread.java:722) caused by: java.lang.illegalargumentexception: exception occured looking on class: class util.feedbackutils constructor using selection criteria types arguments. if criteriaquery not intended constructor query please verify selection matches return type. @ org.eclipse.persistence.internal.jpa.querydef.criteriaqueryimpl.populateandsetconstructorselection(criteriaqueryimpl.java:409) @ org.eclipse.persistence.internal.jpa.querydef.criteriaqueryimpl.select(criteriaqueryimpl.java:93) @ admin.beans.feedbackbean.getlist(feedbackbean.java:145) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:601) @ org.glassfish.ejb.security.application.ejbsecuritymanager.runmethod(ejbsecuritymanager.java:1081) @ org.glassfish.ejb.security.application.ejbsecuritymanager.invoke(ejbsecuritymanager.java:1153) @ com.sun.ejb.containers.basecontainer.invokebeanmethod(basecontainer.java:4695) @ com.sun.ejb.ejbinvocation.invokebeanmethod(ejbinvocation.java:630) @ com.sun.ejb.containers.interceptors.aroundinvokechainimpl.invokenext(interceptormanager.java:822) @ com.sun.ejb.ejbinvocation.proceed(ejbinvocation.java:582) @ org.jboss.weld.ejb.abstractejbrequestscopeactivationinterceptor.aroundinvoke(abstractejbrequestscopeactivationinterceptor.java:46) @ sun.reflect.generatedmethodaccessor478.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:601) @ com.sun.ejb.containers.interceptors.aroundinvokeinterceptor.intercept(interceptormanager.java:883) @ com.sun.ejb.containers.interceptors.aroundinvokechainimpl.invokenext(interceptormanager.java:822) @ com.sun.ejb.ejbinvocation.proceed(ejbinvocation.java:582) @ com.sun.ejb.containers.interceptors.systeminterceptorproxy.docall(systeminterceptorproxy.java:163) @ com.sun.ejb.containers.interceptors.systeminterceptorproxy.aroundinvoke(systeminterceptorproxy.java:140) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:601) @ com.sun.ejb.containers.interceptors.aroundinvokeinterceptor.intercept(interceptormanager.java:883) @ com.sun.ejb.containers.interceptors.aroundinvokechainimpl.invokenext(interceptormanager.java:822) @ com.sun.ejb.containers.interceptors.interceptormanager.intercept(interceptormanager.java:369) @ com.sun.ejb.containers.basecontainer.__intercept(basecontainer.java:4667) @ com.sun.ejb.containers.basecontainer.intercept(basecontainer.java:4655) @ com.sun.ejb.containers.ejblocalobjectinvocationhandler.invoke(ejblocalobjectinvocationhandler.java:212) ... 67 more caused by: java.lang.nosuchmethodexception: util.feedbackutils.<init>(java.lang.long, java.lang.string, java.lang.string, org.joda.time.datetime, java.lang.boolean, java.lang.long, java.lang.string) @ java.lang.class.getconstructor0(class.java:2721) @ java.lang.class.getconstructor(class.java:1674) @ org.eclipse.persistence.internal.security.privilegedaccesshelper.getconstructorfor(privilegedaccesshelper.java:157) @ org.eclipse.persistence.internal.jpa.querydef.criteriaqueryimpl.populateandsetconstructorselection(criteriaqueryimpl.java:396) ... 98 more
this works fine, when type of testimonial
changed boolean
object
in feedbackutils
class.
why not let constructor query work, if given boolean
type in constructor list of parameters?
i'm using eclipselink 2.5.1.
edit :
in constructor of feedbackutils
class, following check,
testimonial.getclass().getname()
returns java.lang.boolean
and of following,
(testimonial instanceof boolean) testimonial.getclass().equals(boolean.class) testimonial.getclass().isassignablefrom(boolean.class)
return true
.
hence, following type cast valid.
(boolean)testimonial
upto associated xhtml page, correctly behaves boolean
.
Comments
Post a Comment