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.  [ 5 posts ] 
Author Message
 Post subject: Concurrency
PostPosted: Thu Sep 28, 2006 12:12 pm 
Newbie

Joined: Thu Aug 17, 2006 7:25 am
Posts: 7
I haved browsed the documentation and forums and can't find an anwser to this question so I was wondering if someone could help me.

I am developing a WinForms application which is storing the Session in a singleton for the life of the application. I call the following code on PC A:

Code:
        public static IList RetrieveAllCustomers()
        {
            return Database.Session.Find("from Customer c order by c.CustomerId asc");
        }


This loads all my customers up correctly.

I then open the app on PC B and insert a new customer. I go back to PC A and call the above code again which correctly returns the new row. However, if I do an update on an existing instance from PC B and then call the retrieve all from PC A the update is not retrieved. I am using the <version> tag btw.

Checking the NHibernate (V1.0.2.0) code (Loader.cs) it seems that NHib just checks whether the object is loaded ; if it is then it just uses that instance otherwise it creates a new instance (i.e. it only picks up new rows).

Am I missing the point here but shouldn't it also check that the versions are the same seeing that it has done the hard work by getting all the rows from the database anyway?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 11:25 pm 
Regular
Regular

Joined: Tue Feb 21, 2006 9:50 am
Posts: 107
did you call Session.Flush() after the update? Session.Update() only updates the internal NHibernate-Cache.

Regards
Klaus


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 3:45 am 
Newbie

Joined: Thu Aug 17, 2006 7:25 am
Posts: 7
Yes, I can see the change in the database by querying it directly in SQL.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 4:43 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
NHibernate uses optimistic locking, so you will get an error if you try to update the stale object. It also assumes that the session is part of a (application) transaction, so the data should stay the same and it will not refresh your objects silently.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 5:26 am 
Regular
Regular

Joined: Tue Aug 08, 2006 4:28 am
Posts: 96
Location: Hong Kong
The session object in PC A actually cached objects that were loaded before. You need to call Session.Refresh() if you know exactly what object is updated by PC B. Or call Session.Clear() before Session.Find() to refresh all objects.


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