Solved

Joins in HQL

Posted on 2009-05-10
7
877 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
  • 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction: I have seen many questions on EE and elsewhere, asking about how to find either gaps in lists of numbers (id field, usually) ranges of values or dates overlapping date ranges combined date ranges I thought it would be a good …
This article describes some very basic things about SQL Server filegroups.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now