-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: HQL question
PostPosted: Wed Sep 27, 2006 8:44 pm 
Newbie

Joined: Wed Sep 06, 2006 10:35 am
Posts: 14
I am just learning about Hibernate (I'm using NHibernate 1.0) and I have a question about HQL.

I have a valid SQL query that I run against my SQL server:

Code:
SELECT t0.col0 AS t0c0, t0.col1 AS t0c1, t0.col2 AS t0c2, t0.col3 AS t0c3
FROM Table0 AS t0
INNER JOIN Table1 AS t1 ON (t0.col1=t1.col1)
INNER JOIN Table2 AS t2 ON (t2.col1=t1.col2)


Assuming each of the tables (Table0, Table1 and Table2) have an associated hibernate-mapped class, what would the corresponding HQL query look like?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 3:51 am 
Beginner
Beginner

Joined: Thu Aug 24, 2006 6:01 am
Posts: 49
Location: sophia-antipolis, France
Assume that you have entities mapped to each table:

Entity0 -> Table0
Entity1 -> Table1
Entity2 -> Table2

and Entity0 contains properties:

Entity1 entity1
Entity2 entity2

Then I could write the HQL like:

Code:
SELECT distinct entity0
FROM Entity0 entity0
INNER JOIN entity0.entity1
INNER JOIN entity0.entity2


I do the inner joins simply because I want to get everything in one SQL query (when the fetching is lazy), but I don't want to fetch other relations which Entity1 and Entity2 might contain.[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 2:25 pm 
Newbie

Joined: Wed Sep 06, 2006 10:35 am
Posts: 14
Thanks! In this case my existing Entity0 does not contain objects of the other two types. The tables just have some loose relations based on the column values and i have to check to make sure the column values match up (see my SQL statement above) and only return those rows that are related to the other two tables in that specific way.

I think I can translate most of the SQL above to HQL but I don't know how to do thigs like "ON (t0.col1=t1.col1)"


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.