?
Solved

Joins in HQL

Posted on 2009-05-10
7
Medium Priority
?
884 Views
Last Modified: 2012-06-27
Hi,
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?

Thanks.
0
Comment
Question by:cuttieveenz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
7 Comments
 
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.

-Murali*
0
 
LVL 46

Accepted Solution

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

http://docs.huihoo.com/hibernate/hibernate-reference-3.2.1/queryhql.html
At the bottom there are examples

Good Luck!

Gary
0
 
LVL 1

Assisted Solution

by:mohgupta
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 -
getsession.saveorUpdate(class1);
0
 
LVL 46

Expert Comment

by:tbsgadi
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 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