-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: how to query sets
PostPosted: Tue Oct 11, 2005 3:34 am 
Newbie

Joined: Tue Oct 11, 2005 3:27 am
Posts: 5
hi all,
i have a prob, is it poss to query hibernate like below
u.userGropu is a set in my class
and user.getUserGroup() also returns a set.

s.find("from User u where u.userGroup='"+user.getUserGroup()+"'" +
"order by u.name");

I get the following error, is there anything i am doing wrong....as querying in a loop while passing each member of set to query seems bad practice.

net.sf.hibernate.QueryException: unindexed collection before []: user0_.userGroup [from com.da.vcrmanager.data.User u where u.userGroup='[com.da.vcrmanager.data.UserGroup@1282707, com.da.vcrmanager.data.UserGroup@1672313]'order by u.name]
at net.sf.hibernate.hql.PathExpressionParser.prepareForIndex(PathExpressionParser.java:308)
at net.sf.hibernate.hql.PathExpressionParser.end(PathExpressionParser.java:292)
at net.sf.hibernate.hql.WhereParser.doPathExpression(WhereParser.java:344)
at net.sf.hibernate.hql.WhereParser.doToken(WhereParser.java:374)
at net.sf.hibernate.hql.WhereParser.token(WhereParser.java:259)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:295)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1572)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1531)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1523)
at com.da.vcrmanager.actions.UserList.getAllStaff(UserList.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:491)
at ognl.OgnlRuntime.getMethodValue(OgnlRuntime.java:904)
at ognl.ObjectPropertyAccessor.getPossibleProperty(ObjectPropertyAccessor.java:54)
at ognl.ObjectPropertyAccessor.getProperty(ObjectPropertyAccessor.java:122)
at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1616)
at com.opensymphony.xwork.util.CompoundRootAccessor.getProperty(CompoundRootAccessor.java:97)
at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1616)
at ognl.ASTProperty.getValueBody(ASTProperty.java:96)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:171)
at ognl.SimpleNode.getValue(SimpleNode.java:193)
at ognl.Ognl.getValue(Ognl.java:333)
at ognl.Ognl.getValue(Ognl.java:310)
at com.opensymphony.xwork.util.OgnlValueStack.findValue(OgnlValueStack.java:143)
at com.opensymphony.webwork.views.jsp.WebWorkBodyTagSupport.findValue(WebWorkBodyTagSupport.java:35)
at com.opensymphony.webwork.views.jsp.IteratorTag.doStartTag(IteratorTag.java:138)
at org.apache.jsp.WEB_002dINF.jsps.userlist_jsp._jspx_meth_ww_iterator_0(userlist_jsp.java:125)
at org.apache.jsp.WEB_002dINF.jsps.userlist_jsp._jspService(userlist_jsp.java:94)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:696)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:474)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:409)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
at com.opensymphony.webwork.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:81)
at com.opensymphony.webwork.dispatcher.WebWorkResultSupport.execute(WebWorkResultSupport.java:109)
at com.opensymphony.xwork.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:258)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:182)
at com.da.utils.interceptors.AuthorizationInterceptor.intercept(AuthorizationInterceptor.java:63)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.da.utils.interceptors.AuthenticationInterceptor.intercept(AuthenticationInterceptor.java:37)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:116)
at com.opensymphony.webwork.dispatcher.ServletDispatcher.serviceAction(ServletDispatcher.java:272)
at com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:237)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.da.utils.SessionManager.doFilter(SessionManager.java:87)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:536)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 1:27 pm 
Newbie

Joined: Wed Mar 30, 2005 8:58 am
Posts: 10
Location: São Paulo / Brazil
If your userGroup attribute is a Collection, you should join it before using it in the where clause.

Code:
from com.foo.User u join u.userGroup ug where ug in ?


And then, inform the filter object (user.getUserGroup()) in the ? position.

Cheers

_________________
www.brunoborges.com.br


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 12:46 am 
Newbie

Joined: Tue Oct 11, 2005 3:27 am
Posts: 5
List list= s.find("from User u join u.userGroup ug"+
" where ug in '"+user.getUserGroup()+"'");

thanks for the reply, but this query seems to have a syntax prob.

WARN - SQL Error: 1064, SQLState: 42000
ERROR - Syntax error or access violation, message from server: "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''[com.da.vcrmanager.data.UserGroup@d18636, com.da.vcrmanager.da"

if these might help, some excerpts from hibernate mappings.

1.User.hbm.xml

<set name="userGroup" table="usergroups" cascade="all" lazy="false">
<key column="user_id" />
<one-to-many class="com.da.vcrmanager.data.UserGroup" />
</set>


2.UserGroup.hbm.xml

<many-to-one name="myUser" cascade="all" class="com.da.vcrmanager.data.User" column="user_id"/>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.