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.  [ 4 posts ] 
Author Message
 Post subject: Optimistic Concurrency and Entity Refresh
PostPosted: Tue Jun 12, 2007 3:47 am 
Newbie

Joined: Tue Jun 12, 2007 2:43 am
Posts: 4
Hi,
I'm developing and Enterprice Application that use NHibernate and some Microsoft's Application Block.
This is the first time that I use NHibernate and I have many problems to implement the optimistic concurrency.
I read the strategies for the optimistic concurrency control in the NHibernate Documentation specially the case "Many Sessions with automatic versioning".

Using Composite User Interface Application Block I create one ISession per WorkItem so I have many sessions and many detached entities.
When the user modify the entities the standard Data Flow is the follow:

[One WorkItem]
1. Load Entities
[An other WorkItem]
2. Modify Entities
3. Update Entities

Now when the user update an entity I call session.Update(...) method and I catch the StaleStateException (In the NHibernate Class Mapping File there are the follow settings: dynamic-update="true" and optimisic-lock="dirty"). When the Exception is catched I want to display an error messange and to ask to the user if reload the entity.
Now, Which is the best way that I must use for the entity reload?
I'm trying to use the session.Refresh(...) method but there is a problem when the user try to save the data after the refresh. The problem is the sql update query that have in the where clause the first entity data and not the refreshed data so the StaleStateException is fired another time.
Where is the mistake?

P.s.: sorry for my broken english.

Regards
Andrea


Top
 Profile  
 
 Post subject: Creating a new session?
PostPosted: Wed Jun 13, 2007 12:41 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
Are you creating a new session for use after the StaleStateException? My understanding is that ISession state becomes inconsistent after it throws an exception, and it should be discarded. It could be a problem if you are calling Refresh on the same ISession that threw the exception.


Top
 Profile  
 
 Post subject: ISession
PostPosted: Fri Jun 15, 2007 3:21 am 
Newbie

Joined: Tue Jun 12, 2007 2:43 am
Posts: 4
Yes I create a new ISession after the StaleStateException. The steps are the follows:
1. Catch StaleStateException
2. Close current ISession
3. Open a new ISession
4. Call session.Refresh(...) method.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 1:22 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
After this I'll have to step aside until someone more knowledgable could look at your question. My only other thought is that your session use pattern may not be compatible with dynamic-update or optimistic-lock="dirty". If the updates are not being done in the context of the same session as the loads, I don't think the ISession can tell which columns have changed values.

This may not be the case... this is where a more expert opinion is needed.


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