This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Query two tables using hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Query two tables using hibernate" Watch "Query two tables using hibernate" New topic

Query two tables using hibernate

Romeo Ranjan
Ranch Hand

Joined: Feb 23, 2009
Posts: 95
I have SQL query

It extracts name,start_date and end_date from the pay table where name at the pay table and emp table are the same and the id=16940 and in the emp table the status must be employed.
How do I implement this SQL query using hibernate? My application uses hibernate, till now it was straightforward I have and that queries the pay table and emp table seperately. But I want to implement the above query in which the result is based on both the tables..How I am supposed to implement it..Can someone please throw some light on the problem or give some example?


SCJP 6.0
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

You can use a Criteria search or HQL. See here for examples.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
I agree. Here's the link:
subject: Query two tables using hibernate
Similar Threads
HQL help needed
retrieving object hierarchy - many-to-one?
named sql-query dilema
Need help in an query development
Why does EJB assume a join table and how do i get around it?