Multiple transaction in same session possible in hibernate??
Mothea Anil Kumar
Greenhorn
Joined: Aug 01, 2005
Posts: 22
posted
0
Hi,
Is it possible to work on more than one transaction with the same hibernate session object ?? I'm getting some problem by doing like this, . . ........ ........
In the above code in while loop , in every condtion i'm creating new transaction and save or updating the object.If any error occurs i'm rollback the transaction. Problem is, if Object is saving means there is no problem. If it's not saving means , I rollback the transaction and for the next objects it's giving the error related to session.(error).
My question is , --> Is it necessery to close the session every time ?? --> Is it not possible to use more than one transation in same session ??
Any body help me please.It's urgent. Thank's in advance.
So I want to update 100 records, Why would I want to create 100 transactions. I would just want one transaction, and if any of the 100 updates/inserts fail, then rollback the transaction. If you have a "Use Case" that takes these 100 objects and want each individual Object to have its own transaction, then I think the Use Case is wrong. That there are 100 different units of work, so different calls.
I can't see a case where you would need multiple transactions like that.
Exactly, so you are taking the Unit of Work definition of one all succeeds or it all fails, and trying to redefine it how you want it. But a Unit of Work is just that, it all succeeds or all fails, you cannot change what that means. So it is a matter of relooking at your use case. I suggest getting the JDBC connection directly out of the Session and work at that level to get what you want, or create one session per update.
Mark
Saathvik Reddy
Ranch Hand
Joined: Jun 03, 2005
Posts: 228
posted
0
If it's not saving means , I rollback the transaction and for the next objects it's giving the error related to session.(error).
Could you post the error!
Hanna Habashy
Ranch Hand
Joined: Aug 20, 2003
Posts: 532
posted
0
When you commit the transaction, the session will be flushed and closed, hence you will get an error. you might want to try to set the FlushMode.never so the session will never be flushed automatically.
SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Originally posted by Hanna Habashy: When you commit the transaction, the session will be flushed and closed, hence you will get an error. you might want to try to set the FlushMode.never so the session will never be flushed automatically.
Yes, but you have to flush, manually or automatically at some point to send the statements to the database, and any exception you get will cause the entire transaction to rollback.
Mark
subject: Multiple transaction in same session possible in hibernate??