-->
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: Hibernate query using multipe tables
PostPosted: Mon May 18, 2009 6:42 am 
Newbie

Joined: Mon May 18, 2009 5:45 am
Posts: 1
Hi guys,

I have an SQL query which I need to translate to Hibernate:

SELECT * FROM LeaseCars
JOIN Contract ON Contract.LeaseCarID = LeaseCars.LeaseCarID
WHERE Contract.ContractStatus = HISTORY;

Already got this piece of Hibernate code to work:

public List<Car> getUnusedCars()
{
return baseDAO.getCarsByCriteria(Restrictions.eq("carStatus",
"0"), Restrictions.eq("brand", "Subaru"));
}

This uses one table, so I'm stuck on joining multiple tables in one query. Anyone knows how to do this? I am completely new to Hibernate so please go easy on me :)


Top
 Profile  
 
 Post subject: Re: Hibernate query using multipe tables
PostPosted: Tue May 19, 2009 3:26 pm 
Newbie

Joined: Sat Nov 29, 2008 10:56 am
Posts: 8
Have you defined associations between the tables in hbm files? Once you have done that you can create aliases to the relevant tables using criteria object and it will do the joins for you.


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.