-->
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.  [ 5 posts ] 
Author Message
 Post subject: org.hibernate.impl.SQLQuery.iterate not implemented
PostPosted: Sat Jan 28, 2006 10:20 am 
Newbie

Joined: Thu Nov 17, 2005 1:29 pm
Posts: 12
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1
Mapping documents:

Code between sessionFactory.openSession() and session.close():

I have a named query that works just fine, so I haven't included it. The query is run against a SQLServer db. I would like to iterate over the results, so I wrapped my ScrollableResults with an iterator. Is there some reason that this is crazy, because if not, why wouldn't the implementation of iterate in SQLQueryImple not just do something like this?

Code:
public Iterator visitUnmappedCardVendors(final int companyId) {
      ScrollableResults scroll = (ScrollableResults) getHibernateTemplate().execute( new HibernateCallback() {
         public Object doInHibernate(Session session) throws HibernateException {
            Query queryObject = session.getNamedQuery("mapped_vendors_with_company_supplier_key");
            //prepareQuery(queryObject);
            queryObject.setParameter("companyId", Integer.toString(companyId));
            return queryObject.scroll();
         }
      }, true);   
      return new ScrollableResultsIterator(scroll);
   }
   
   private class ScrollableResultsIterator implements Iterator {
      public boolean hasNext() {
         return !this.results.isLast();
      }
      public Object next() {
         boolean rv = this.results.next();
         if (rv ) {
            return this.results.get();
         }
         throw new NoSuchElementException("After last element.");
      }
      public void remove() {
         // noop.
      }
      private ScrollableResults results;
      public ScrollableResultsIterator(ScrollableResults results) {
         this.results = results;
      }
   }


Thanks for the help.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 10:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
you need to read the document regarding Query.iterate()

iterate() essentially performs a "shallow query" first for entity returns to just get their ids. As you iterate over the returned iterator, Hibernate then does additional selects to initialize the entities. obviously this is not possible in situations where you supply the sql query to be used.


Top
 Profile  
 
 Post subject: about iterating
PostPosted: Sat Jan 28, 2006 4:56 pm 
Newbie

Joined: Thu Nov 17, 2005 1:29 pm
Posts: 12
steve wrote:
you need to read the document regarding Query.iterate()

iterate() essentially performs a "shallow query" first for entity returns to just get their ids. As you iterate over the returned iterator, Hibernate then does additional selects to initialize the entities. obviously this is not possible in situations where you supply the sql query to be used.



I see, so what I'm doing wouldn't solve iterate, because it's not what 'iterate' does for a query.

However, is what I'm doing acceptable with respect to interacting with the ScrollableResults?


Anyway, thanks for the Info.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 7:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
to be completely correct, you should make sure that the underlying ScrollableResults gets closed at some point.


Top
 Profile  
 
 Post subject: closing ScrollableResults
PostPosted: Sat Jan 28, 2006 7:26 pm 
Newbie

Joined: Thu Nov 17, 2005 1:29 pm
Posts: 12
steve wrote:
to be completely correct, you should make sure that the underlying ScrollableResults gets closed at some point.


I see. I figured that's what was missing.


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