-->
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: Hibernate JDBC batch update
PostPosted: Tue Mar 07, 2006 11:30 am 
Regular
Regular

Joined: Tue Mar 07, 2006 11:18 am
Posts: 54
Location: Berlin
Hi there,
we are working on an application with about 150 entities and a class hirachie where a certain amount of different "Dokuments" are mapped to a "Table per Class" - DB mapping.
In one special case we have to do a batchupdate like the code below.
I set the hibernate.jdbc.batch_size to 50 to use the advantage of JDBC batching.
My question is, does this configuration has any side effects to the rest of my application or could they appear somewhere?

Do you have any experience with these kind of batchupdates?

Hibernate version: 3.0

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

Session session = getHibernateSession();
try{
Transaction transaction = session.beginTransaction();
Criteria criteria = getHibernateSession().createCriteria(getDaoType());

addRestriction4Serie(criteria, serieId);
if ( suchtext != null ) {
criteria.add(Restrictions.ilike("titel", suchtext));
}
criteria.add(Restrictions.ne("boostFaktor",new Float(boostFaktor)));
long startTime = System.currentTimeMillis();
ScrollableResults results = criteria.setCacheMode(CacheMode.IGNORE).scroll(ScrollMode.FORWARD_ONLY);
long count = 0;

while(results.next()){
Dok dok = (Dok)results.get(0);
dok.setBoostFaktor(boostFaktor);
session.saveOrUpdate(dok);
if((++count % 50) == 0){
session.flush();
session.clear();
}
}

transaction.commit();
if(LOG.isInfoEnabled())
LOG.info("Updated "+count+" Rows; Run batchupdate in " +((System.currentTimeMillis()-startTime)/1000)+" seconds");
}catch (Throwable e) {
DAOException ex = new DAOException("Exception in "
+ getClass().getName() + ".setBoostFaktor() " + e.getMessage());
ex.setStackTrace(e.getStackTrace());
throw ex;
}finally{
session.close();
}


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.