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.  [ 7 posts ] 
Author Message
 Post subject: Synchronize a single object loaded in two separate sessions?
PostPosted: Wed Oct 26, 2005 7:13 pm 
Hello,

I'm fairly new to HNibernate. I've been building a small prototype for my development team which will be used as a basis for our project. But I do have some questions that I was hoping someone could help me with first:

a) Say I open a session, load some info from a table into the corresponding object, then close the session. Then I modify some data in the object. If I were to open another session and try to save the object using the new session, will the data that I changed be persisted?

b) Say two people open separate sessions, load some info from the same table (same record also) into separate objects. Person A makes some change to his object, and updates it to the database. Person B makes some changes to his object and attempts to update it to the database. What happens? Is there any synchronization method to handle dirty objects?

Any help is appreciated.

Thank you.


Top
  
 
 Post subject:
PostPosted: Thu Oct 27, 2005 10:22 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
a) Yes

b) If you didn't added <version> (or <timestamp>), the last save will overwrite the previous.
Else, it will throw an exception...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 31, 2005 3:10 pm 
KPixel wrote:
a) Yes

b) If you didn't added <version> (or <timestamp>), the last save will overwrite the previous.
Else, it will throw an exception...


Thank you for your quick reply.

However, for b), I don't quite understand how the versioning works. Does this mean that if two people are updating the same object, there will be two records persisted in the database? Who is responsible for re-associating these two records? And what if re-associating them causes a conflict? Eg, maybe both people updated the same field on the record to a different value.

I've been reading up on row locking, and I'm thinking that this may also be an option. Does anyone have any suggestions or examples on how to do this?

Any help is appreciated.

Yogindra


Top
  
 
 Post subject:
PostPosted: Tue Nov 01, 2005 4:24 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
<version> is used to apply Optimistic Locking.

Practical example:
You load an entity; its version if "3" (or any date/time if timestamp). When you save it the version became "4" (or DateTime.Now).
So if two users load the same object, they both get "3"; then the first save, it became "4" and when the second try to save, NHibernate find that the version is no longer "3" which means that someone else update this entity/row and it throws an exception! (here, you should ask to the second user to re-load this entity to re-apply his changes).

Do some research on the internet to find more information...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 01, 2005 4:59 pm 
Thanks once again for the quick reply. This makes total sense now.

Regards.


Top
  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 9:00 pm 
Newbie

Joined: Wed Jun 21, 2006 2:45 pm
Posts: 16
I have stupid question: for versioning, do I have to create a column in the database for this?

If not, how is it tracking this versioning number in the Session?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 4:03 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Yes, you need to create a DB Column. The info is in the docs.

Cheers,

Symon.


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