java - hibernate query for list<t> in where clause -
i've @manytomany
mapped classes in spring application want of tasks i've assigned particular user id.
task class
public class task { @id @generatedvalue(strategy=generationtype.auto) @column(name="taskid") private string taskid; @column(name="subject") private string subject; @manytomany(fetch=fetchtype.eager) @jointable(name = "jt_assign_tasksmap", joincolumns = { @joincolumn(name = "taskid") }, inversejoincolumns = { @joincolumn(name = "assignedto_uid") }) private list<users> to; //getters , setters }
user class
public class users { @id @generatedvalue(strategy=generationtype.auto) @column(name = "uid") private string id; @column(name = "username") private string username; @manytomany(targetentity=task.class, mappedby="to", fetch = fetchtype.eager, cascade=cascadetype.all) @fetch(fetchmode.select) private list<task> assignedto; //getters , setters }
now want list tasks of user.
i tried above code didn't work
public list<task> getallofmytasks(string userid) { list<string> ids = new arraylist<string>(); ids.add(userid); return (list<task>) sf.getcurrentsession().createquery("from task to.id = :userid").setparameterlist("userid", ids).list(); }
error is
http status 500 - request processing failed; nested exception org.hibernate.queryexception: illegal attempt dereference collection [{synthetic-alias}{non-qualified-property-ref}to] element property reference [id] [from com.nbtech.powertrac.model.task to.id = :userid] org.springframework.web.util.nestedservletexception: request processing failed; nested exception org.hibernate.queryexception: illegal attempt dereference collection [{synthetic-alias}{non-qualified-property-ref}to] element property reference [id] [from com.nbtech.powertrac.model.task to.id = :userid] org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:979) org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:858) javax.servlet.http.httpservlet.service(httpservlet.java:622) org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:843) javax.servlet.http.httpservlet.service(httpservlet.java:729) org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:316) org.springframework.security.web.access.intercept.filtersecurityinterceptor.invoke(filtersecurityinterceptor.java:126) org.springframework.security.web.access.intercept.filtersecurityinterceptor.dofilter(filtersecurityinterceptor.java:90) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) org.springframework.security.web.access.exceptiontranslationfilter.dofilter(exceptiontranslationfilter.java:114) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) org.springframework.security.web.session.sessionmanagementfilter.dofilter(sessionmanagementfilter.java:122) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) org.springframework.security.web.authentication.anonymousauthenticationfilter.dofilter(anonymousauthenticationfilter.java:111) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) org.springframework.security.web.servletapi.securitycontextholderawarerequestfilter.dofilter(securitycontextholderawarerequestfilter.java:168) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) org.springframework.security.web.savedrequest.requestcacheawarefilter.dofilter(requestcacheawarefilter.java:48) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) org.springframework.security.web.authentication.www.basicauthenticationfilter.dofilterinternal(basicauthenticationfilter.java:158) org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) org.springframework.security.web.authentication.abstractauthenticationprocessingfilter.dofilter(abstractauthenticationprocessingfilter.java:205) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) org.springframework.security.web.authentication.logout.logoutfilter.dofilter(logoutfilter.java:120) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) org.springframework.security.web.csrf.csrffilter.dofilterinternal(csrffilter.java:96) org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) org.springframework.security.web.header.headerwriterfilter.dofilterinternal(headerwriterfilter.java:64) org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) org.springframework.security.web.context.request.async.webasyncmanagerintegrationfilter.dofilterinternal(webasyncmanagerintegrationfilter.java:53) org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) org.springframework.security.web.context.securitycontextpersistencefilter.dofilter(securitycontextpersistencefilter.java:91) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) org.springframework.security.web.filterchainproxy.dofilterinternal(filterchainproxy.java:213) org.springframework.security.web.filterchainproxy.dofilter(filterchainproxy.java:176) org.springframework.web.filter.delegatingfilterproxy.invokedelegate(delegatingfilterproxy.java:344) org.springframework.web.filter.delegatingfilterproxy.dofilter(delegatingfilterproxy.java:261)
the point to
collection. usual way filter criteria on collection elements join first:
select distinct t task t join t.to tto tto.id = :userid
Comments
Post a Comment