-->
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: left join condition.Is it possible to translate to Criteria?
PostPosted: Mon Mar 09, 2009 6:43 am 
Newbie

Joined: Mon Mar 09, 2009 6:30 am
Posts: 2
Hi,

Is it possible to translate the next SQL to Criteria API?

select a.id, b.name, b.value

from a

left join a_b on (a_b.id_a=a.id and a_b.id_b=1)

left join b on (a_b.id_b=b.id)

I don´t know translate the condition in 'left join' ( and a_b.id_b=1)

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 09, 2009 6:32 pm 
Newbie

Joined: Tue Mar 03, 2009 12:50 pm
Posts: 5
Location: New York
this should be possible, by simply putting that extra condition in the WHERE clause.

e.g. without knowing your classes or mapping, something like (fragment only...)

session.createCriteria(A.class)
.createAlias("aBMap","a_b")
.add( Restrictions.eq("a_b.id",1) )
....

just a quick answer, you'll need to look up some stuff above, but i hope it helps...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 10, 2009 4:40 am 
Newbie

Joined: Mon Mar 09, 2009 6:30 am
Posts: 2
kshih wrote:
this should be possible, by simply putting that extra condition in the WHERE clause.

e.g. without knowing your classes or mapping, something like (fragment only...)

session.createCriteria(A.class)
.createAlias("aBMap","a_b")
.add( Restrictions.eq("a_b.id",1) )
....

just a quick answer, you'll need to look up some stuff above, but i hope it helps...


Thank you kshih but your query it isn´t valid for me.
I want the condition is in left outer join and not in 'where' clause because
the results are very diferent

A and B are entities.
A_B is the relationship table (don´t exist mapping)

Thanks for trying


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 11, 2009 4:15 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
try to use
Code:
Criteria criteria = session.createCriteria(A.class);
criteria.createAlias("aBMap", "a_b", Criteria.LEFT_JOIN);
...



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.