I use session.iterate() to retrieve a list of records. I know that the first time I issue the iterate, that it should return nothing. However, it still reports hasNext as true. Here is a code snipit:
public class SegmentTypeServices {
protected static Logger logger = Logger.getLogger(SegmentTypeServices.class.getName());
public static int nextSegmentTypeCode(ControlEventContext context) throws HibernateException, AppConfigError {
Session hbSession = HibernateSession.currentSession();
Iterator maxCodeList = hbSession.iterate("select max(sgType.comp_id.sgTypeCode) from com.orci.ITSAM.hibernate.SegmentType sgType " +
"where sgType.comp_id.siteDatabase.comp_id.site = ? " +
"and sgType.comp_id.siteDatabase.comp_id.dbId = ? ",
new Object[] {
SiteDatabaseServices.MyDbSiteCode(context),
SiteDatabaseServices.MyDbId(context) },
new Type[] {
Hibernate.INTEGER,
Hibernate.INTEGER });
if (!maxCodeList.hasNext()) return 1;
Object[] row = (Object[])maxCodeList.next();
return ((Integer)row[0]).intValue();
}
When I run it I get a java.util.NoSuchElementException: No more results exception.
Any ideas?
Thanks in advance,
David Robison
|