-->
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.  [ 3 posts ] 
Author Message
 Post subject: iterator.hasNext()
PostPosted: Wed Dec 10, 2003 11:07 pm 
Newbie

Joined: Wed Dec 10, 2003 10:45 pm
Posts: 6
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()
.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 12:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This was a bug that is fixed in CVS. Actually the query returns a single row, containing null.


Top
 Profile  
 
 Post subject: found it!
PostPosted: Thu Dec 11, 2003 4:33 am 
Newbie

Joined: Wed Dec 10, 2003 10:45 pm
Posts: 6
A quick search for "hasNext" in JIRA yield:

HB-524 "iterate shows hasNext=true when nothing returned"

Thanks Gavin!


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