-->
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: using hibernate for batch jobs, when to create Session
PostPosted: Wed Mar 30, 2011 6:24 pm 
Newbie

Joined: Wed Mar 30, 2011 6:19 pm
Posts: 1
so i think i understand the open session in view pattern when generally used with controllers and creating a filter which creates the hibernate session and starts the transaction and then there are multiple service calls for that http request.

im trying to do the same thing for batch jobs but running into some issues.

so i have a set of batch jobs, and for each one, it calls a service to get a list of objects. it does this in the batch class. then for each object, it will make a service call to process the object. i have this call in the batch class wrapped in a try catch, so if an exception occurs, i log it, but iw ant the next object to be processed and persisted.

i was creating a hibernate session in this batch class and binding it to the current thread - this was so that the session used to get the list of objects is the same session used to process each object since in the services it might call object.getList which is lazy loaded (can only be loaded from that same session). but im not creating a transaction in that batch class either because these batch jobs can run long, and if the db timeout is at 5 min i'll get an error saying the db connection closed for this outer transaction (since each service call will have an inner transaction)

but there was a problem w/ this when say the first object in the list threw an exception in the service, then when i process the 2nd object and try to access something from the obj that's lazy loaded, it will say there's no session. this seems to be because im not actually supposed to reuse a session after an exception occurs since hibernate does something to it..?

any ideas on how to resolve this?

whats the best way to go about doing something like this? it seems like something that's really common for batch jobs - getting a list of objects, and process each one independently of the other (persisting it and if exception occurs, doesnt affect persisting of the others).

thanks


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.