• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How to map multiple tables in Hibernate query

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 3 tables that i would like to take values from each table and return them as a list later on.

My current attempt is creating the query. Since i am using Hibernate tool, i use session.createSQLQuery in Dao class.

These are the table i want to call:
1. Booking
2. User
3. Venue

This what i made so far in Dao class:


If i use HQL instead, how does the query be like?
 
Saloon Keeper
Posts: 24325
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I really recommend using Hibernate JPA instead of legacy Hibernate. One day the legacy version is going to lack support.

But the process is basically the same in both versions of Hibernate. You establish relationships between the 3 tables using constructs such as the @OneToMany/@ManyToOne linkages. Then you determine what you want to use for a working set. Say, for example, that I want to get all Bookings for a Venue on a certain date. I'd make a query that might look something like this:


That would return a collection of bookings (note that I didn't ORDER BY, since I wasn't interested details like that). Since a Booking has a Venue, we look through its venue member (ManyToOne) to match on the ID of the venue we want.

Now we can get venue details from the booking using its getVenue() method to see the venue record. Hibernate has automatically done the SQL JOIN operations out of sight.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You establish relationships between the 3 tables using constructs such as the @OneToMany/@ManyToOne linkages. Then you determine what you want to use for a working set.omegle online
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic