-->
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.  [ 2 posts ] 
Author Message
 Post subject: request problem
PostPosted: Thu Dec 21, 2006 12:28 pm 
Newbie

Joined: Thu Dec 21, 2006 11:01 am
Posts: 12
Hi all !

I have three tables with one relation one-to-many.
Example :

Enterprise (idEnterprise, Name)
TargetCountry (idEnter, targetCountry)
Country(countryName)

And I would like to query the countries from the enterprise id.
This is the sql request :

SELECT Country.countryName FROM Country, TargetCountry, Enterprise WHERE Country.countryName = TargetCountry.countryName AND TargetCountry.idEnter = Enterprise.idEnterprise AND Enterprise.idEnteprise = 2;

That's it ... I tried to do this request in hql and with a criteria too, but I don't now really for which reason it doesn't work !

Tanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 1:11 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
What do look like your objects? Think about objects to do this query. Something like

Code:
Country yourCountry = (Country)session.createQuery("from Country c inner join c.enterprise").uniqueResult();


(uniqueResult() is an helper method on the session to be used when waiting for one result exactly)

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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