• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How to map multiple tables in Hibernate query

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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: 22483
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
I suggest huckleberry pie. But the only thing on the gluten free menu is this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic