-->
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: Batch loads and transactions
PostPosted: Mon Feb 09, 2009 5:26 pm 
Newbie

Joined: Mon Feb 09, 2009 5:00 pm
Posts: 2
Hibernate version: 3.2.6
Spring version: 2.5.3

Our product works on a batch of users to run a particular unit of work on each user. We envision a design were we are using the Hibernate batch load process (batch-size="10" specified in the .hbm) to retrieve a batch of say 10 users and then pass it to our "worker" that will then do whatever needs to be done.

Now, in order for this to work right, I have an outer transaction which does the loading of the user and makes any changes on the user that might need to be done prior to the call to the worker. Once the user is created, he is then passed to the worker and run within its own transaction boundary (a new transaction - PROPAGATION_REQUIRES_NEW). The idea being that if there was a failure with the worker's transaction boundary, then we can rollback any updates to the user inside the worker. Note, I do not want to have to rollback ALL the users in my batch in the event of a failure on one user's processing. Obviously, this also implies that the completion of my worker should save any updates to the user.

My problem is this: Since the user was "loaded" as a batch, the outer transaction (and hence, session) is what is managing the user entity. So, in order for my worker's rollback (and flush, for that matter) to act on the user entity, I find myself having to evict() the user out of the original transaction once I hand over control to my worker (so that the outer transaction does not override my worker changes) and have the worker explicitly merge() the user back so as to be managed by my worker transaction. I have this working with code, but I have concerns about this. The entire reason for this code is because I started a new transaction - which is configured via spring XML, but here I have had to code in the implications of the new transaction creation.

Have others faced this delimma and if so, how have you solved it?

I am toying with the idea of using an interceptor to do this and have it configured via spring when I set up the transaction for a worker.

Madhuri


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.