-->
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: Update many entities under JBoss
PostPosted: Thu Aug 26, 2004 11:45 am 
Newbie

Joined: Wed Jun 16, 2004 9:54 am
Posts: 7
Hello,

I'm using Hibernate 2.14 and JBoss 3.24 and I'm trying to update a large number of objects (160000). I know that you shouldn't use Hibernate for something like this, but I would like test Hibernate a little bit. The problem is, that I'm always running out of memory.
The code (in a stateless session bean) looks like this:

Code:
public boolean massUpdate()  {
   try {
       Session session = HibernateUtil.getSession();
       HibernateUtil.beginTransaction();
         
       int batch = 1;
       Iterator fs = session.iterate("from foobar");
       Foobar foobar;
       while ( fs.hasNext() ) {
              foobar = (Foobar) fs.next();
              foobar.setValue(foobar.getValue()+5);

              // flush ever thousand updates:
              if (batch%1000 == 0) {
                     session.flush();
                     session.clear();
              }
              batch++;
       }
       HibernateUtil.commitTransaction();         
   }
   catch (HibernateException e) {
       HibernateUtil.rollbackTransaction();
       e.printStackTrace()
   }
   finally {
       HibernateUtil.closeSession();         
   }
   return true;            
}


Is there something wrong with the code?

Thanks a lot,
Jonas


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.