-->
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.  [ 7 posts ] 
Author Message
 Post subject: dynamic criteria list
PostPosted: Thu Aug 18, 2005 4:19 am 
Beginner
Beginner

Joined: Fri Jul 16, 2004 3:21 am
Posts: 40
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0.5

I want to make a dynamic critaria list:

i want to select all my adresses with the country spain,france, andorra.

table Adress:
ID : number
name : varachar
surname : varachar
city : varachar
phone : varachar
country : varachar

how can i do that with a criteria.
during runtime the list of countries varied. so i seek somthing that i can give the cirteria a java.util.List or Set.

rgds stefan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 4:37 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi Stefan

Try this


Criteria crt = sess.createCriteria(new YourClass());
if(info.getCountry() != null)
crt.add(Expression.eq("country",info.getCountry()));
List list = crt.list() ;

This is for getting a value for a single Country.

You can create a ArrayList and then add the country in to the list and pass it in the Expression.

crt.add(Expression.eq("country",ArrayList));

I dont remember the syntax check it out.

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 4:47 am 
Beginner
Beginner

Joined: Fri Jul 16, 2004 3:21 am
Posts: 40
Thanks Ramnath

i will try this.
is crt.add(Expression.eq("country",ArrayList));
then a "AND" betweend the different Members of the ArrayList or are this Members with "OR" linked?

rgds stefan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 5:15 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi Stefan

Its AND

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 5:16 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Sorry

Its OR

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 4:20 pm 
Beginner
Beginner

Joined: Fri Jul 16, 2004 3:21 am
Posts: 40
Hello Ramnath

it works, thanks for the help.

here the code:

Code:
ArrayList countryList = new ArrayList();
countryList.add("Switzerland");
countryList.add("Germany");
countryList.add("France");
Criteria critetria=  session.createCriteria(Adress.class);
critetria.add(Expression.in("Country",countryList));
List <Adress>list = critetria.list();
for (Adress adress : list) {
     // iterate through
}


rgds stefan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 11:42 pm 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi Stefan

You forgot to rate my posting

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


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