-->
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.  [ 5 posts ] 
Author Message
 Post subject: joining on unrelated entities' properties
PostPosted: Wed Mar 29, 2006 5:19 pm 
Regular
Regular

Joined: Mon Sep 29, 2003 9:39 am
Posts: 67
Hibernate version:
3.0

Two classes that have similar composite keys, with 2 properties mapped as many-to-one and the third key, a Date.

would like to do something like:
Code:
X.id.a = Y.id.a and
X.id.b = Y.id.b
where X.id.date <= Y.id.date


The key classes are different because the Date maps to a different column name, xDate vs. yDate.

Is this type of 'unrelated' join possible? (how or alteratives?).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 6:03 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
this should work :
select X, Y
where
X.id.a = Y.id.a
and X.id.b = Y.id.b
and X.id.date <= Y.id.date

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: Possiblie with outer join?
PostPosted: Thu Mar 30, 2006 5:12 pm 
Regular
Regular

Joined: Mon Sep 29, 2003 9:39 am
Posts: 67
Thanks, that got me a few steps closer to what I'm trying to do. Now, I have a third relationship that is used to implement a "waterfall": get Z's property first if there is a z, otherwise get X's property.

Given this scenario:

select X, Y
where
X.id.a = Y.id.a
and X.id.b = Y.id.b
and X.id.date <= Y.id.date

need:

select X, Y, Z
where
X.id.a = Y.id.a
and X.id.b = Y.id.b
and X.id.date <= Y.id.date
and X.id.a *= Z.id.a
and X.id.b *= Z.id.b

My understanding is that theta-style outer joins are not implemented in hql. It would seem like the native sql query would be more complex than the jdbc sql. Any suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 5:16 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
For this kind of situations I recommend supplementing Hibernate with I batis, or if you need heavy SQL optimization then just use iBatis

http://sandbox.sourcelabs.com/kosta/hb- ... batis.html

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 10:27 pm 
Regular
Regular

Joined: Mon Sep 29, 2003 9:39 am
Posts: 67
Konstantin,

Thanks for the link to the excellent site. I'm not sure if we'll be able to add ibatis at this point, but the solution sounds good. Hopefully hibernate will support what you suggest[url=http://sandbox.sourcelabs.com/kosta/hb-beyond-hw/java/com/sourcelabs/hibernate/bhw/sql/doc/cooperating_with_sql.html]
here[/url] in the future.

Thanks for your help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.