-->
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.  [ 6 posts ] 
Author Message
 Post subject: HQL help please
PostPosted: Fri Apr 22, 2005 11:53 am 
Newbie

Joined: Fri Apr 22, 2005 11:31 am
Posts: 4
Location: Liverpool, UK
Hi,
I'm working with the PetClinic demo which comes with Spring.
I thought I'd make some changes to it so I could learn how it works, but have come up against some difficulties.

I decided to allow Vets (instead of just Owners) to have Pets.
vets(id[s], firstName, lastName[/s])
(with the restriction that vets.id must be from owners.id - owners should now be 'people')

Anyway, I have tried replacing the previous
return getHibernateTemplate().find("from Vet vet order by vet.lastName, vet.firstName");
with
return getHibernateTemplate().find("from Vet vet, Owner owner where vet.id = owner.id");
which doesn't in itself return errors, but it does seem to lead to errors.

The errors are below, but seem to imply that the returned results is a set of owners not vets. (suggesting that my HQL is duff).

I understand that I haven't included much, but as a newbie it is hard knowing what's relevant.

Any help/suggestions/questions are very much appreciated.


Full stack trace of any exception that occurs:
javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "value" with value "${vet.firstName}": The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array, but that value cannot be converted to an integer. (null) at org.apache.taglibs.standard.lang.jstl.Evaluator.evaluate(Evaluator.java:109) at org.apache.taglibs.standard.lang.jstl.Evaluator.evaluate(Evaluator.java:129) at org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager.evaluate(ExpressionEvaluatorManager.java:75) at org.apache.taglibs.standard.tag.el.core.ExpressionUtil.evalNotNull(ExpressionUtil.java:48) at org.apache.taglibs.standard.tag.el.core.OutTag.evaluateExpressions(OutTag.java:99) at org.apache.taglibs.standard.tag.el.core.OutTag.doStartTag(OutTag.java:57) at org.apache.jsp.WEB_002dINF.jsp.vets_jsp._jspx_meth_c_out_0(vets_jsp.java:192) at org.apache.jsp.WEB_002dINF.jsp.vets_jsp._jspx_meth_c_forEach_0(vets_jsp.java:147) at org.apache.jsp.WEB_002dINF.jsp.vets_jsp._jspService(vets_jsp.java:96) 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:237) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:704) 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 org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:97) at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250) at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:917) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:696) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:623) at org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:384) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:344) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) 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.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:117) 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:683) at java.lang.Thread.run(Thread.java:595) Cookies: JSESSIONID=[986338DFB190EA2D17D576D9A87C999C]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 1:23 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
try use projection like :

select vet.id, vet.lastName... from Vet vet,Owner owner ...

regards


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 1:27 pm 
Newbie

Joined: Fri Apr 22, 2005 11:31 am
Posts: 4
Location: Liverpool, UK
oh sorry, looks like this forum doesn't use the [s] tag,
the vet table no longer holds anything other than the foriegn id.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 25, 2005 4:26 am 
Newbie

Joined: Fri Apr 22, 2005 11:31 am
Posts: 4
Location: Liverpool, UK
I know you guys don't like bumps, but I did post this at a silly time before.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 25, 2005 7:38 am 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
If you do not include select in your HQL, your result set will, by default, be a list of object arrays, where the elements of the object arrays are the relevant objects per-row of the HQL query results - IF you are choosing to return multiple Hibernate Objects per row.

In your example, the resulting List will look like a List of Object[] where index[0] is probably a Vet, and index[1] is probably an Owner. Using common debugging/debugger techniques would let you find out for yourself.

I assume in your JSP you are looping through the list, assuming each element is a Vet object (if the HQL returns only one type of object, it will be returned as a List of that object, e.g. List<Vet>). Your JSP broke, because the List elements are now Object[].

Makes sense?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 25, 2005 9:52 am 
Newbie

Joined: Fri Apr 22, 2005 11:31 am
Posts: 4
Location: Liverpool, UK
that makes sense, and I can see why the JSP broke, but I really need someone to explain what HQL I need since I've been unable to find useful references. (The official page is rather poor imho.)

I imagine most people using HQL are very familiar with (my)SQL and as such would find it easier than I am.

I think I need some kind of Join query, is that right?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.