-->
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.  [ 5 posts ] 
Author Message
 Post subject: HQL - foreign key
PostPosted: Mon Nov 28, 2005 2:03 pm 
Newbie

Joined: Thu Oct 20, 2005 5:25 am
Posts: 14
Hello,

I hope s.o. can help me.

How is it possible with a HQL-statement to say the where-clause, that it should look after the foreign key?

My case:

Entities: Teil and Disponent

in Teil is the key from Disponent. Now I want this:

"select teilId from Teil where disponentId like ?"

But I don't know how to write "disponentId". In my tabele "Reichweite" of the Database it is called "disponent_disponent_id".
In the Entity Disponent it is calles "disponentId" and in the Entity Teil it is a one-to-many association called "disponentAssoziation" (Hashset).

Thanks, if anyone could help!

greetz
bande


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 28, 2005 3:13 pm 
Newbie

Joined: Wed Nov 23, 2005 6:25 pm
Posts: 10
Location: Austin, Texas
If you want a List<Teil> where the disponentID like ?, try this:

Code:
select t
from Teil t
join t.disponentAssoziation disponent
where disponent.disponentId like ?


If you want just a List<int> then do:

Code:
select t.teilId
from Teil t
join t.disponentAssoziation disponent
where disponent.disponentId like ?


The trick is that you need to join in the one-to-many association so that HQL knows what Entity you want to perform your WHERE clause on.

-HTH


Top
 Profile  
 
 Post subject: deleted
PostPosted: Mon Nov 28, 2005 6:16 pm 
Newbie

Joined: Thu Nov 24, 2005 2:19 am
Posts: 10
deleted


Last edited by ramin_farhanian on Fri Jun 06, 2014 11:33 pm, edited 3 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 5:46 am 
Newbie

Joined: Thu Oct 20, 2005 5:25 am
Posts: 14
Hi MustangCorder,

I tried this

Code:
String queryString = "select t.teilId from Teil t join t.disponentAssoziation disponent where disponent.disponentId like ?";
List resultList = session.createQuery(queryString).setLong(0, disponent.getDisponentId().longValue()).list();


but always get the error-message:

javax.servlet.ServletException: javax.servlet.jsp.JspException: javax.faces.el.EvaluationException: Error getting property 'anzahlDoppelblitz' from bean of type business.LoginBean: org.hibernate.HibernateException: Not able to obtain connection
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:844)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.Eingangskorb_jsp._jspService(org.apache.jsp.Eingangskorb_jsp:95)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
org.jenia.faces.template.handler.ViewHandler.renderView(ViewHandler.java:74)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)



I don't know why! I hope you or s.o. else could help me.

Thanks for the replies.

bande


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 6:04 am 
Newbie

Joined: Thu Oct 20, 2005 5:25 am
Posts: 14
ok, this was my fault! the session weas closed before by another method.

thanks for your helps. it worked fine :-)


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