-->
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: Can I define my own joins ?
PostPosted: Wed Aug 18, 2004 9:52 am 
Newbie

Joined: Wed Aug 18, 2004 9:45 am
Posts: 9
Location: Warsaw, Poland
Hibernate version:
2.1.6

Question:
Can I define my own join in Hibernate HQL ? I don't want to define it in mapping xml files.
I need to build query like this (native SQL):

SELECT *
FROM CONSULTANT_PLAN
LEFT JOIN CONSULTANT_WEEK ON
(CONSULTANT_PLAN.ID = CONSULTANT_WEEK.IDUSER
AND DATE > '2004-06-28 00:00:00.000'
AND DATE < '2004-07-02 00:00:00.000')
ORDER BY NAME DESC, DATE

where date values need to be set dynamically.
It is a little different than that (this can be done easily using HQL and mapping files) :

SELECT *
FROM CONSULTANT_PLAN
LEFT JOIN CONSULTANT_WEEK ON CONSULTANT_PLAN.ID = CONSULTANT_WEEK.IDUSER
WHERE
(DATE > '2004-06-28 00:00:00.000'
AND DATE < '2004-07-02 00:00:00.000')
ORDER BY NAME DESC, DATE

which gives you other results.

Greetings
Tom Kucharski


Top
 Profile  
 
 Post subject: inner/right/left join on clause
PostPosted: Thu Aug 19, 2004 8:06 am 
Newbie

Joined: Wed Aug 18, 2004 9:45 am
Posts: 9
Location: Warsaw, Poland
Hibernate version:
2.1.6

I need to build query like this:

from Model1 model1 inner join Model2 model2 on model1.foreignModel2 = model2.primaryId


I don't want to use mapping files because I must define join there explicity, not dynamically. Apart from that, how can I build such query ???
I think Hibernate don't let me build such query.


from Model1 model1 inner join Model2 model2 on model1.foreignModel2 = model2.primaryId and model1.someValue < 5


Thanks for any reply.
Tom Kucharski


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 19, 2004 8:22 am 
Regular
Regular

Joined: Wed Aug 18, 2004 5:16 am
Posts: 69
Location: Modena, Italy
You can, read http://www.hibernate.org/hib_docs/refer ... yhql-joins


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 19, 2004 8:31 am 
Newbie

Joined: Wed Aug 18, 2004 9:45 am
Posts: 9
Location: Warsaw, Poland
Thanks.

There is nothing more than creating simple join query using join definition described in mapping file(s) on this site.

I've read this tutorial really carefully.
I've also read 'Hibernate in Action' book but I haven't found any explanation for this problem.


Anyway, thanks for reply.
Tom Kucharski


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 21, 2004 3:20 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No, you can't declare your own outer join condition in Hibernate 2. (I think this is in the documentation and in the book, but certainly in the FAQ.)

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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.