-->
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: How to expedite batch updates ?
PostPosted: Fri Sep 30, 2011 5:20 am 
Newbie

Joined: Mon Sep 19, 2011 9:37 am
Posts: 3
We have a scenario where we need to perform several updates, but not for all columns.

Code:
Session session = ...
session.beginTransaction();

for () {
object.setPrimaryKey(key);
object.setProperty(value);
object.setAnotherProperty(value);

session.update(object);

if ( i % 3000 == 0 ) {
    session.flush();
    session.clear();
}         
}
.. commit ...


Regardless of how many properties are present, hibernate generates an UPDATE sql for all columns which will fail for a column with a NON-NULL constraint, for which we aren't setting anything. Even if there is no constraint, we do not wish to wipe out the existing value. To work around, we first load the object and update only the selected value.

I have noticed that the batch is fast if we can avoid the load.

Is there any better way to achieve this ? We can try out the conventional ways and cache the objects, but does hibernate offer anything we might have missed here.


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.