-->
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: Criteria help
PostPosted: Thu May 24, 2007 3:21 am 
Newbie

Joined: Thu May 24, 2007 3:01 am
Posts: 11
Hi,
I am using Hibernate criteria for my QuickSearch. ITs just one text field. We can enter any one of the items like id, first name, lastname, branch etc. in that field and click search. In criteria i must use logical or expression.
i.e Select * ...where id=? or firstname=? or lastname=? or branch=?.

How can i write criteria code for this?

my code is like this,

Criterion firstName = Restrictions.eq("borrower.firstName", astrParam.trim());
Criterion lastName = Restrictions.eq("borrower.lastName", astrParam.trim());
LogicalExpression ORExpression = Expression.or(firstName, lastName);

I want to add more criterions like this.

YOur help is appreciated.

Thank you,
K. Siva


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 5:08 am 
Regular
Regular

Joined: Thu Nov 23, 2006 10:29 am
Posts: 106
Location: Belgium
Hello,

You might consider using Junction (Conjunction/Disjunction) to avoid using a lot of OrExpressions:

Code:
ICriteria crit = session.CreateCriteria(typeof(Entity));
Junction junction = new Disjunction();
junction.Add(new LikeExpression("name", "%name%"));
junction.Add(new LikeExpression("firstname", "%firstname%"));
...
crit.Add(junction);
IList<Entity> entities = crit.List<Entity>();


What this does is basically using an OR to concatenate your expressions, surrounded by brackets.

_________________
Please rate this post if it helped.

X.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 6:11 am 
Newbie

Joined: Thu May 24, 2007 3:01 am
Posts: 11
Thanx xasp.

But i think you can't create junction object thro' constructor.(I got error) I am not sure. I am coding like this,

Disjunction junction = Expression.disjunction();

Thanks a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 6:17 am 
Regular
Regular

Joined: Thu Nov 23, 2006 10:29 am
Posts: 106
Location: Belgium
Hi,

Why not just creating it like in the example, and adding it the the Criteria-obect ?

_________________
Please rate this post if it helped.

X.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 7:15 am 
Newbie

Joined: Thu May 24, 2007 3:01 am
Posts: 11
I dont have ICriteria. Also when i code
Junction junction = new DisJunction() ;
I have error new DisJunction() is not visible. Anyway thanx to you for your valuable help. I solved my problem.


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.