-->
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.  [ 4 posts ] 
Author Message
 Post subject: JPA-QL equivalent for a LEFT-JOIN criteria for ON clause
PostPosted: Tue Feb 15, 2011 5:19 pm 
Regular
Regular

Joined: Fri Jul 30, 2004 4:02 pm
Posts: 50
Hey all,
Ran into a specific challenge with Left Joins. This site gave me the SQL answer, but unsure of the JPA-QL approach to solve the problem: http://forums.devshed.com/oracle-develo ... 83248.html

Inline example of the LEFT JOIN criteria for the ON clause below just in case link doesn't work:
Code:
select departments.dept_id
     , finances.title
     , finances.month
     , finances.year
     , finances.revenue
     , finances.expenses
  from departments
left
  join finances
    on departments.dept_id = finances.dept_id
   and finances.month = 2
   and finances.year = 2006
order
    by dept_id


The
and finances.month = 2
and finances.year = 2006

in the ON criteria are the important part I'm not sure how to do in JPA-QL (or in creating the associations).

Thanks for any help!

-D


Top
 Profile  
 
 Post subject: Re: JPA-QL equivalent for a LEFT-JOIN criteria for ON clause
PostPosted: Wed Feb 16, 2011 5:54 am 
Regular
Regular

Joined: Fri Jan 28, 2011 11:44 am
Posts: 117
Hi,

Before trying to write your query in JPA-QL there is one thing you should know, since Hibernate 3.1.3 the conditions in the ON clause can only refer to the right hand side of the join (in your case: finances). So "on departments.dept_id = ..." will generate an error!

http://opensource.atlassian.com/project ... e/HHH-1930


Top
 Profile  
 
 Post subject: Re: JPA-QL equivalent for a LEFT-JOIN criteria for ON clause
PostPosted: Wed Feb 16, 2011 6:01 am 
Regular
Regular

Joined: Fri Jan 28, 2011 11:44 am
Posts: 117
Sorry for the double post,

I've been a little too quick at answering your question.
In fact you should be able to write your query in JPA-QL.
If you define a One-To-Many relationship between departments and finances then the condition "on departments.dept_id = finances.dept_id" will be automatically created by Hibernate (you won't have to put it in your HQL query) and you shouldn't have any problem ...


Top
 Profile  
 
 Post subject: Re: JPA-QL equivalent for a LEFT-JOIN criteria for ON clause
PostPosted: Wed Feb 16, 2011 9:39 am 
Regular
Regular

Joined: Fri Jul 30, 2004 4:02 pm
Posts: 50
Ah, thank you - so 'with' is the magic word, using the example in the link:
Code:
Person p join p.emailAddresses as email with email = 'xyz'


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