-->
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.  [ 3 posts ] 
Author Message
 Post subject: Adding restrictions to a disjunction with multiple aliases
PostPosted: Wed Mar 18, 2009 12:16 pm 
Newbie

Joined: Wed Jan 04, 2006 2:29 pm
Posts: 8
Hi,
I'm trying to add several restrictions to a disjunction while using two aliases. Is this possible?
My Breakdown class is associated to a Elevator and GhostElevator classes and I'd need to check conditions on both these associations.

While

Code:
DetachedCriteria criteria = DetachedCriteria.forClass(Breakdown.class)
      .createAlias("ghostElevator", "ghost")
         .add(Restrictions.disjunction()
               .add(Restrictions.in("ghost.suggestedSociety.id", societies)));

with criteria created:
Quote:
DetachableCriteria(CriteriaImpl(it.linksystem.csai.model.Breakdown:this[Subcriteria(ghostElevator:ghost)][(ghost.suggestedSociety.id in (26, 4))]))

while this and the other criteria work separately if I do a disjunction on both:
Code:
DetachedCriteria criteria = DetachedCriteria.forClass(Breakdown.class)
      .createAlias("elevator", "el")
      .createAlias("ghostElevator", "ghost")
         .add(Restrictions.disjunction()
               .add(Restrictions.in("ghost.suggestedSociety.id", societies))
               .add(Restrictions.in("el.society.id", societies)));

I don't get any results back, even though the criteria seems reasonable:
Quote:
DetachableCriteria(CriteriaImpl(it.linksystem.csai.model.Breakdown:this[Subcriteria(elevator:el), Subcriteria(ghostElevator:ghost)][(ghost.suggestedSociety.id in (26, 4) or el.society.id in (26, 4))]))


Is having more than one alias not supported with the Criteria API or am I creating the criteria in a wrong way?

Hibernate version: 3.2.6

Full stack trace of any exception that occurs:

Name and version of the database you are using:Postgresql 8.3


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 18, 2009 12:35 pm 
Regular
Regular

Joined: Mon Jan 05, 2009 6:42 pm
Posts: 99
Location: IL
Can you post the generated SQL for both of the HQL queries ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 18, 2009 1:23 pm 
Newbie

Joined: Wed Jan 04, 2006 2:29 pm
Posts: 8
The default join that an alias creates is a inner join, therefore you should use the other alias constructor
Code:
.createAlias("elevator", "el", Criteria.LEFT_JOIN)
.createAlias("ghostElevator", "ghost", Criteria.LEFT_JOIN)


thanks go to sebersole on #hibernate


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