-->
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.  [ 1 post ] 
Author Message
 Post subject: Using ScrollableResults throwing unexpected exception
PostPosted: Wed Jul 24, 2013 3:39 am 
Newbie

Joined: Wed Jul 24, 2013 3:24 am
Posts: 2
Hi all,

I am using ScrollableResults within streaming mode

For some reason in the while loop I am having an exception:

Code:
11:54:24,182  WARN SqlExceptionHelper:143 - SQL Error: 0, SQLState: null
    11:54:24,182 ERROR SqlExceptionHelper:144 - Streaming result set com.mysql.jdbc.RowDataDynamic@729d8721 is still active. No statements may be issued when any streaming result sets are open and in use on a given connection. Ensure that you have called .close() on any active streaming result sets before attempting more queries.
    11:54:24,183  WARN CollectionLoadContext:347 - HHH000160: On CollectionLoadContext#cleanup, localLoadingCollectionKeys contained [3] entries
    Exception in thread "Thread-11" java.lang.RuntimeException: Could not export



Code:
My scroller:

    protected void scroll(ScrollableHandler<T> handler,String namedQuery, Object... values){
          T previousEntity=null;
          Session s = null;
          ScrollableResults results = null;
          try {
             s = (Session) em.getDelegate();
             org.hibernate.Query query = s.getNamedQuery(namedQuery);
             for (int i = 0; i < values.length; i++)
                query.setParameter(i, values[i]);
             results = query.setFetchSize(fetchSize).scroll(ScrollMode.FORWARD_ONLY);
             while(results.next()) -> [color=#FF0040] here I get the exception[/color]
                        {
                T entity = (T) results.get(0);
                if (null != entity &&
                      (! entity.equals(previousEntity))) {
                   doSomething(entity);
                   previousEntity = entity;
                }
                s.clear();
             }
          } finally {
             if (results != null)
                results.close();
          }
        }




I know I should have only one select while opening connection when using Scrolling.

But here is the thing: When I am using the scroller I see an additional select in the log files:

Code:
11:54:24,165 DEBUG SQL:104 - select userpart0_.id as id1_11_0_, ........
[b]11:54:24,181 DEBUG SQL:104 - select distributo0_.id as id1_1_1_,........[/b]
11:54:24,182  WARN SqlExceptionHelper:143 - SQL Error: 0, SQLState: null
11:54:24,182 ERROR SqlExceptionHelper:144 - Streaming result set com.mysql.jdbc.RowDataDynamic@729d8721 is still active. No statements may be issued when any streaming result sets are open and in use on a given connection. Ensure that you have called .close() on any active streaming result sets before attempting more queries.
11:54:24,183  WARN CollectionLoadContext:347 - HHH000160: On CollectionLoadContext#cleanup, localLoadingCollectionKeys contained [3] entries
Exception in thread "Thread-11" Java. Lang. RuntimeException: Could not export
   at com...run(MyClass.java:59)
   at java.lang.Thread.run(Thread.java:724)
....


I tried again to get the same data without using scroller. then did iteration on all record and watched the log file. I coudlnt see additional selectes beside the big one:

Code:
protected void regularNamedQuery(ScrollableHandler<T> handler,String namedQuery, Object... values){
   
               
           Query query = em.createNamedQuery(namedQuery);
         for (int i = 0; i < values.length; i++)
            query.setParameter(i+1, values[i]);
         
         List<UserPart> a = query.getResultList();
         
         for (int x=0;x<a.size();x++)
         {
            System.out.println(a.get(x).getDistributorPart().getTaxonomyPath());
         
         }
}


The system.out from the second code (regularNamedQuery) were:

39/622
39/622
39/622
39/622

Maybe that will give a hint?

All my data entities in the @ManyToOne are Lazy fetched (@ManyToOne(fetch = FetchType.LAZY))

I also have oneToMany relations in my statement. Maybe that's causing the problem?

Thanks for your help,
ray.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.