Solved

Joins in HQL

Posted on 2009-05-10
7
882 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 125 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 125 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

Upcoming Webinar: Securing your MySQL/MariaDB data

Join Percona’s Chief Evangelist, Colin Charles as he presents Securing your MySQL®/MariaDB® data on Tuesday, July 11, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

687 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