-->
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.  [ 3 posts ] 
Author Message
 Post subject: Batch Update is not working
PostPosted: Fri Jan 22, 2010 11:48 am 
Newbie

Joined: Fri Jan 15, 2010 1:42 pm
Posts: 4
I followed an example in the tutorial/book to the letter, scrolling with the cursor, flushing, clearing the context.
It has worked; however, the sql log showed updates as separate statements. I went further to profile the database (sql server).
The profiler again showed that execution happened in a non-batching manner.

I tried to debug Hibernate source code, but could see that when the batching is called for
in org.hibernate.engine.ActionQueue.executeActions(List) with
session.getBatcher().executeBatch() -> org.hibernate.jdbc.AbstractBatcher.executeBatch(),
internal batchUpdate (PreparedStatement) is null, preventing batch execution.

I have been looking around for a long time, but failed to find what needs to happen for batch to work.
I did set hibernate.jdbc.batch.size in persistence.xml and hibernate.cfg.xml files.
I am using annotations if that helps.

Please help! I am trying to move our company towards Hibernate.
Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Batch Update is not working
PostPosted: Sun Jan 24, 2010 6:16 am 
Newbie

Joined: Fri Jan 15, 2010 1:42 pm
Posts: 4
Turns out Hibernate does batching only if the app is not using optimistic locking OR
(the entity is not versioned && use optimistic locking) OR the property hibernate.jdbc.batch_versioned_data
is set to true.

This can be seen in the code here org.hibernate.persister.entity.AbstractEntityPersister.isBatchable()
My code had @Version on a column/

SQL Server execution profile does not seem to differ though: statement declaration followed by N executions.
Though, batching does seem to make run time for the update faster.

Another way to batch updates/inserts, etc is with session.doWork().


Top
 Profile  
 
 Post subject: Re: Batch Update is not working
PostPosted: Mon Jan 25, 2010 9:41 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Hi,

I did make some experience with Hibernate & Batch-updates on SQLServer2008.
It worked to me already with the first try (I use a @Version column in each entity class),
anyway the performance gain was not very remerkable:
It was ca. 10% faster than without batching (I must mention here that we have a fast network).

I used
Code:
<property name="hibernate.jdbc.batch_size" value="1000"/>
<property name="hibernate.order_inserts" value="true"/>
<property name="hibernate.order_updates" value="true"/>

on large transaction where I do perform more than 1000 insert and updates per flush or commit.

If there raises a SQLException during batch-updates, then the message is not so clear and precise as without batching.
Due this disadvantage I personally will use batching only during data-migration but not afterwards in the live-system.


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