-->
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: Left join in hbernate
PostPosted: Mon Jan 24, 2011 4:32 am 
Newbie

Joined: Mon Jan 24, 2011 4:23 am
Posts: 3
I want to implement left joi n but not getting how to do?
query is:
select a.id,a.name,b.value from tableA a left join tableB b on a.id=b.id and b.typeid=5
where a.status =1 and a.type in(1,2)


Top
 Profile  
 
 Post subject: Re: Left join in hbernate
PostPosted: Mon Jan 24, 2011 8:43 am 
Beginner
Beginner

Joined: Thu Feb 08, 2007 10:40 am
Posts: 46
Code:
select
  a.id, a.name, b.value
from
  tableA a
  left join a.tableB b
where
  b.typeid=5 and
  a.status=1 and
  a.type in(1,2)

tableB is the name of the property within object A that defines the mapping between tableA and tableB in your object mapping.


Top
 Profile  
 
 Post subject: Re: Left join in hbernate
PostPosted: Mon Jan 24, 2011 8:54 am 
Newbie

Joined: Mon Jan 24, 2011 4:23 am
Posts: 3
I have to use left join filtered by two columns of tableB. One is the pprimary key of tableA that is foreign key on tableB as well as another column of tableB.
So, I have written

select a.id,a.name,b.value from tableA a left join tableB b on a.id=b.id and b.typeid=5
where a.status =1 and a.type in(1,2)


Top
 Profile  
 
 Post subject: Re: Left join in hbernate
PostPosted: Mon Jan 24, 2011 9:07 am 
Beginner
Beginner

Joined: Thu Feb 08, 2007 10:40 am
Posts: 46
You cannot specify an "on-clause" in HQL. The part that is usually in the on-clause when you are writing SQL has to be in the Hibernate mapping. If your additional filter b.typeid=5 is not part of the mapping, you cannot specify it diretly with the join. However, you should be able to put it in the where clause.


Top
 Profile  
 
 Post subject: Re: Left join in hbernate
PostPosted: Tue Jan 25, 2011 12:35 am 
Newbie

Joined: Mon Jan 24, 2011 4:23 am
Posts: 3
I will look into my mapping for this implementation..
Thanks for your suggestion.


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.