After looking over some other code, I found out what I needed to do to get the sample to close the cursor:
Apparently it needs surrounding query with transaction and cursor then closed upon commiting...
Code:
Transaction trx=sess.beginTransaction();
Query q=sess.getNamedQuery("getPeople");
q.setString (0,"John");
Person p=null;
ScrollableResults sr = q.scroll();
for(int jj=0;(sr.next()); jj++)
{
p=(Person) sr.get(0);
System.out.println("p.PERSON_ID=" + p.getPERSON_ID());
System.out.println("p.FIRST_NAME=" + p.getFIRST_NAME());
System.out.println("p.LAST_NAME=" + p.getLAST_NAME());
}
sr.close();
trx.commit();
Even my original sample will close cursors, when you surround the Query in a transaction.
I think this is related to David's comments:
http://forum.hibernate.org/viewtopic.php?t=956660&highlight=
but I am not sure. Now I am really curious as to why a transaction w/ commit is needed for a Query, aside from the obvious mechanical reason shown above.
Also - for fyi :
I tried closing the ScrollableResults directly and that was not sufficient to close the cursor.
I also tried Hibernate.close(itr);
got an exception (IllegalArgumentException: not a Hibernate iterator)... but I couldn't create a hibernate iterator, since that is created from (Query q) q.iterate(); and that throws an UnsupportedOperationException "SQL queries do not currently support iteration". So apparently that "q.iterator()" only works with HQL queries; and not named Queries ...