-->
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.  [ 2 posts ] 
Author Message
 Post subject: Criteria.list method is not working...
PostPosted: Mon Apr 12, 2004 2:23 pm 
Newbie

Joined: Thu Apr 01, 2004 2:19 pm
Posts: 14
I have the following method in my class:

public List list(Properties criteria) throws PersistenceException {

if(criteria == null) {
return null;
}

Session session = null;
try {
session = sessFactory.openSession();
Criteria crit = session.createCriteria(EditTrailPersistenceManager.class);

Iterator iter = criteria.keySet().iterator();

while(iter.hasNext()) {
String fieldName = (String)iter.next();
String value = criteria.getProperty(fieldName);
System.out.println(fieldName + "---" + value);
if(fieldName.equalsIgnoreCase("id")) {
crit.add( Expression.eq("id", new Long(value)) );
}
else if(fieldName.equalsIgnoreCase("name")) {
crit.add( Expression.eq("name", value) );
}
else if(fieldName.equalsIgnoreCase("actualScore")) {
crit.add( Expression.eq("actualScore", new Long(value)) );
}
else if(fieldName.equalsIgnoreCase("forecastScore")) {
crit.add( Expression.eq("forecastScore", new Long(value)) );
}
else if(fieldName.equalsIgnoreCase("groupId")) {
crit.add( Expression.eq("groupId", new Long(value)) );
}
else if(fieldName.equalsIgnoreCase("division")) {
crit.add( Expression.eq("division", value) );
}
}

return crit.list();
}
catch(HibernateException he) {
he.printStackTrace();
throw new PersistenceException(he);
}
finally {
if(session != null) {
try {
session.close();
}
catch(HibernateException he) {
throw new PersistenceException(he);
}
}
}
}


I call the method as below:


Properties p = new Properties();
p.setProperty("division", "FLNA");
List l = scPMgr.list(p);
System.out.println("SIZE = " + l.size());

There is a record in the database with Division as FLNA, but I get the an empty list !!

Can someone tell me what could be the issue....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 5:22 pm 
Beginner
Beginner

Joined: Fri Mar 26, 2004 8:19 am
Posts: 49
try Expression.like() ?


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