Joins in HQL

Posted on 2009-05-10
Medium Priority
Last Modified: 2012-06-27
I want to get data from two table by using a join. Since I am using Hibernate, I want to use HQL. Can someone please help me with writing joins in HQL?

Question by:cuttieveenz
  • 2
LVL 13

Expert Comment

by:Murali Murugesan
ID: 24351026
establish the relationship using hibernate annotations or in the .hbm file and then do a normal hql to fetch the records which would automatically fetch the related records based on the join condition.

LVL 46

Accepted Solution

tbsgadi earned 500 total points
ID: 24352601
Have a look at the following:

At the bottom there are examples

Good Luck!


Assisted Solution

mohgupta earned 500 total points
ID: 24383007
You first need to the mapping file like hibernate.hbm.xml and then need to declare class for each table in dtatabase ,you wish to use. In config file define database connection properties "*.cfg.xml"

 In mapping file specify the relationship between class and the table i.e mapping class to table. For using joins on tables you need to specify relationships like "one to one", "one to many".

To create a query and execute you can write some thing like this:
 getSession().createquery("from class1,class2 where para1: =para2");
To save or update call -
LVL 46

Expert Comment

ID: 24620680
The question was "Can someone please help me with writing joins in HQL?"

Certainly in the link I gave there were enough examples to get the auther started.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
In this article, we will show how to detach and attach a database and then show how to repair a corrupt database and attach it, If it has some errors. We will show how to detach and attach using SSMS or using T-SQL sentences.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question