Hi,
I want to retrieve the max value for a column and I followed the example code for scalar queries except for the (Object []) cast, I got a classCast exception without it. Now I am getting a null pointer exception. The message "Wierd. row is null" gets printed. I tried to run it with and without valid data in the DB. In one case "Wierd. retVal is null." gets printed. Source code:
Code:
private int getLastDataRecNum(int feedId)
throws HibernateException
{
String qryString =
"select max(ord.DataRecNumInFile) from myPackage.ASIOrder ord where ord.ASIFeedId = " + feedId;
Transaction transaction = _session.beginTransaction();
Iterator result = _session.iterate(qryString);
transaction.commit();
if (result.hasNext()) {
Object[] row = (Object []) result.next();
if (row == null) {
System.out.println("Wierd. row is null.");
return -1;
}
Integer retVal = (Integer) row[0];
if (lastDataRecNum == null) {
System.out.println("Wierd. retVal is null.");
return -1;
}
return retVal.intValue();
}
return -1;
}
Regards,
Vaishali
Code: