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....
|