-->
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: Criteria API Left Join
PostPosted: Wed Mar 19, 2008 6:25 am 
Newbie

Joined: Tue Dec 11, 2007 4:17 am
Posts: 3
Hello,

I would like to ask how (and if it is possible) to use Criteria API to create a query, which would have OR condition that either something matches in the (left) joined table or something matches in the base table.

Example: I want to get all persons which have status 'Active' or belong to some group.

Pseudo code:

ICriteria crit = session.CreateCriteria(typeof(Person));

crit.CreateCriteria("PersonGroup",JoinType.OuterLeftJoin);

crit.Add(Expression.Or(Expression.Eq("Status","Active")
Expression.Eq("PersonGroup","Some Group"))));

^ This is an error as the criteria API does not know to which table the condition belongs to.

Any help appreciated

Makli


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 19, 2008 1:52 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
You should use the CreateCriteria morphism that allows an alias to be set. You can then use thusly defined aliases to disambiguate your properties.

It isn't altogether clear that you need to use CreateCriteria() for the PersonGroup... you might be able to get away with CreateAlias(). I don't know if it actually less expensive, but it doesn't create a new ICriteria instance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 20, 2008 11:56 am 
Newbie

Joined: Tue Dec 11, 2007 4:17 am
Posts: 3
marcal, thanks for the reply.

I can create alias but the expression (Expression.Eq for example) takes parameter "propertyName". So am I supposed to pass alias and property name together? Like string 'TableAlias.PropertyName'? Or is the syntax different?

Thank you


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.