-->
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.  [ 6 posts ] 
Author Message
 Post subject: multiple transactions with the same entity
PostPosted: Thu Nov 04, 2010 7:52 am 
Newbie

Joined: Wed Dec 16, 2009 9:55 am
Posts: 6
Hi All,

I wrote a small app that fetches a bunch of records from the db, processes each one and then saves it in the db.

a transaction is opened before the fetch, committed after the first object is processed and then new transactions are created and committed for each object.

What i see happening is that only the first entity is saved to the DB , the following ones are not saved.

If i commit all objects at once it works, or if i do a new fetch within each transaction, but not one fetch and multiple commits.

IS this behaviour by design?
how can I change it?
is it possible to at least know if the entity is not in the right state and wont persist?

Thanks,
Shay


Top
 Profile  
 
 Post subject: Re: multiple transactions with the same entity
PostPosted: Thu Nov 04, 2010 6:41 pm 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
Post code.


Top
 Profile  
 
 Post subject: Re: multiple transactions with the same entity
PostPosted: Fri Nov 05, 2010 7:37 am 
Newbie

Joined: Wed Dec 16, 2009 9:55 am
Posts: 6
code is pretty complex and cropping to a small size is a bit tricky.

I guess the main question is what happnes to entities that have been fetched as part of a transaction, which is now closed. should they still be valid?

since hibernate doesnt have nested transactions, how do objects behave when they are part of multiple transactions.

Shay


Top
 Profile  
 
 Post subject: Re: multiple transactions with the same entity
PostPosted: Fri Nov 05, 2010 11:10 am 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
shay1680 wrote:
I guess the main question is what happnes to entities that have been fetched as part of a transaction, which is now closed. should they still be valid?


The are valid, of course. Just lazy fetched parts may malfunction.

shay1680 wrote:
since hibernate doesnt have nested transactions, how do objects behave when they are part of multiple transactions


Hibernate is not a transaction manager. It is up to you to control your transactions. But, basically, detached object does not care about transactions. They are simple JavaBeans in the same way as your own constructed JavaBeans would be.

That why I think your code contains some obvious error. I do not think transactions are to blame.


Top
 Profile  
 
 Post subject: Re: multiple transactions with the same entity
PostPosted: Fri Nov 05, 2010 4:35 pm 
Newbie

Joined: Wed Dec 16, 2009 9:55 am
Posts: 6
does a commit detach an object?

how can i tell if an object is detached or not?

Whats the best way to re-attach?

thanks,
Shay


Top
 Profile  
 
 Post subject: Re: multiple transactions with the same entity
PostPosted: Sat Nov 06, 2010 12:29 pm 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
shay1680 wrote:
does a commit detach an object?


No.

shay1680 wrote:
how can i tell if an object is detached or not?


Not sure. Try "Session.get()".

shay1680 wrote:
Whats the best way to re-attach?


A lot of ways to do that. For example use "Session.saveOrUpdate()", or "save", or "persist", or "merge", or read the manual :)


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