Hello,
I might be missing something here. When iterator.hasNext() was used to check the result returned by a scalar query - "Select max(ESR.createDate) ... " - which shouldn't have returned anything, hasNext() returned true and when iterator.next() was called, a
java.util.NoSuchElementException: No more results was thrown.
Why does iterator.hasNext() still returns true when the where-clause does not match anything in a scalar query?
Code:
String query = "SELECT max(ESR.createDate) " +
"FROM com.stc.cm.esr.hibernate.codegen.PatchedFile as PatchedFile " +
" INNER JOIN PatchedFile.esr as ESR " +
"WHERE PatchedFile.file = ? AND ESR.createDate < ?";
....
ESR esr = null;
try
{
Session s = sf.openSession();
Iterator i = s.iterate(query,
new Object[] {fileName, date},
new Type[] {Hibernate.STRING, Hibernate.TIMESTAMP});
if( i.hasNext() )
{
esr = (ESR) s.iterate(findByCreateDate,
(Date) i.next(),
Hibernate.TIMESTAMP).next();
}
....
"java.util.NoSuchElementException: No more results" is thrown at
Code:
(Date) i.next()
.