-->
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: Scroll loop exception session close
PostPosted: Mon Apr 29, 2013 6:18 am 
Regular
Regular

Joined: Thu Jun 16, 2011 12:03 pm
Posts: 94
Hi all,

I want to share my problem with you because after several days trying to make work my app, it still doesn't work....

I work with Hibernate, Hibernate Search and EJB3. I want to loop all rows of a table (about 400000) to create RDF files and to send it to 4Store SPARQL server.

I have an Hibernate Search code that loops perfectly all rows:

Code:
FullTextSession fulltextsession = Search.getFullTextSession(session);
       
fulltextsession.purgeAll(entity);
fulltextsession.flushToIndexes();
fulltextsession.getSearchFactory().optimize(entity);
fulltextsession.clear();
       
fulltextsession.beginTransaction();
       
Criteria query = fulltextsession.createCriteria(entity)
            .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
            .setCacheMode(CacheMode.IGNORE)
            .setFetchSize(1)
            .setFlushMode(FlushMode.MANUAL);
       
ScrollableResults scroll = query.scroll(ScrollMode.FORWARD_ONLY);
       
int batch = 0;
scroll.beforeFirst();
while (scroll.next())
{
            batch++;
            fulltextsession.index(scroll.get(0));

            if(batch % batchSize == 0)
            {
                fulltextsession.flushToIndexes();
                fulltextsession.clear();
                log.debug("Clase:" + entity + " flushToIndexes() batch: " + batch );
               
                fulltextsession.getTransaction().commit();
                fulltextsession.beginTransaction();
            }
}
scroll.close();
       
fulltextsession.getTransaction().commit();
       
fulltextsession.getSearchFactory().optimize(entity);


But, if I loop using the Hibernate session instead the fulltextsession, after 30 minutes, it throws an exception like this one:

Code:
2013-04-29 11:03:10,875 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA-12117 TransactionReaper::check timeout for TX 0:ffff7f000101:126a:517e15b7:e9 in state  RUN
2013-04-29 11:03:10,875 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA-12095 Abort of action id 0:ffff7f000101:126a:517e15b7:e9 invoked while multiple threads active within it.
2013-04-29 11:03:10,875 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA-12108 CheckedAction::check - atomic action 0:ffff7f000101:126a:517e15b7:e9 aborting with 1 threads active!
2013-04-29 11:03:10,895 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA-12121 TransactionReaper::doCancellations worker Thread[Transaction Reaper Worker 0,5,jboss] successfully canceled TX 0:ffff7f000101:126a:517e15b7:e9
2013-04-29 11:03:10,905 INFO  [STDOUT] (http-0.0.0.0-8080-1) 29/04/2013 11:03:10 - DEBUG - Create 5982 ed: 201 imported successfully
2013-04-29 11:03:10,905 INFO  [STDOUT] (http-0.0.0.0-8080-1) This is a 4store SPARQL server v1.1.4
2013-04-29 11:03:10,905 INFO  [STDOUT] (http-0.0.0.0-8080-1) 
2013-04-29 11:03:10,905 WARN  [org.hibernate.util.JDBCExceptionReporter] (http-0.0.0.0-8080-1) SQL Error: 0, SQLState: null
2013-04-29 11:03:10,905 ERROR [org.hibernate.util.JDBCExceptionReporter] (http-0.0.0.0-8080-1) The result set is closed.
2013-04-29 11:03:10,906 INFO  [org.jboss.resource.connectionmanager.CachedConnectionManager] (http-0.0.0.0-8080-1) Closing a connection for you.  Please close them yourself: org.jboss.resource.adapter.jdbc.jdk6.WrappedConnectionJDK6@1162908d
2013-04-29 11:03:10,906 WARN  [com.arjuna.ats.arjuna] (http-0.0.0.0-8080-1) ARJUNA-12077 Abort called on already aborted atomic action 0:ffff7f000101:126a:517e15b7:e9
2013-04-29 11:03:10,908 ERROR [org.jboss.wsf.common.invocation.InvocationHandlerJAXWS] (http-0.0.0.0-8080-1) Method invocation failed with exception: null: java.lang.reflect.InvocationTargetException




The looping code is this one:

Code:
     Criteria query = session.createCriteria(Entity.class)
                       .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
                     .setCacheMode(CacheMode.IGNORE)
                     .setFetchSize(1)
                     .setReadOnly(true);
       
     session.beginTransaction();
       
     ScrollableResults scroll = query.scroll(ScrollMode.FORWARD_ONLY);
       scroll.beforeFirst();
      
    Store store;
      
    int batch = 0;
    while (scroll.next())
    {
       log.debug("add4StoreRDF batch :" + batch++);
             
       store = new Store("http://localhost:8000");
             
        Entity ed = (Entity) scroll.get(0);
             
   String response = store.add("http://www.example.com/" + ed.getId(), ed.getRDF(), Store.InputFormat.XML);
                
        // i tried this code to avoid timeout exception, but it still does not work
        if(batch == 100)
   {
             session.getTransaction().commit();
             session.beginTransaction();
             batch = 0;
   }
}

scroll.close();
session.getTransaction().commit();


Any ideas on how to loop all rows of one table?

thanks in advance


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.