-->
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.  [ 8 posts ] 
Author Message
 Post subject: Session.Refresh doesn't work for many-to-one associations
PostPosted: Wed Jul 04, 2007 5:48 pm 
Newbie

Joined: Wed Jul 04, 2007 5:31 pm
Posts: 17
NHibernate version: NHibernate 1.2

Session.Refresh method doesn't reload many-to-one associations.

I have object X with many-to-one association Y (lazy). Y is mapped
like this:
<many-to-one name="_y" access="field" column="Y_ID" cascade="all"/>

- Calling Session.Refresh (X) reloads only X.
- However Session.Evict(X) and then Session.Refresh(X) reloads both X and Y objects.

The reason i want to Refresh object is just a Cancel button on a dialog.
(i want to discard changes made to X).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 12:07 pm 
Newbie

Joined: Wed Jul 04, 2007 5:31 pm
Posts: 17
Does anybody know the answer on this?

According to documentation Refresh is used to reload object and it's
collections:

>> It is possible to re-load an object and all its collections at any time, using the Refresh() method.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 12:55 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Many-to-one associations are not considered to belong to the object, unlike collections, that's why they are not refreshed. You'll have to refresh them manually.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 2:22 pm 
Newbie

Joined: Wed Jul 04, 2007 5:31 pm
Posts: 17
Thanks for reply!

I set cascade style of association to "all". Doesn't it mean that it will
include "refresh". This if from hibernate doc:

>>>>
Setting a value of the cascade attribute to any meaningful value other than none will propagate certain operations to the associated object. The meaningful values are the names of Hibernate's basic operations, persist, merge, delete, save-update, evict, replicate, lock, refresh, as well as the special values delete-orphan and all and comma-separated combinations of operation names, for example, cascade="persist,merge,evict" or cascade="all,delete-orphan"
>>>>

======
I think that my problem is rather typical - i have a dialog that
is used to edit object X and it's associations. If user made some
changes to object X and pressed Cancel button on dialog i want
to discard those changes.

Is it a correct solution to call Evict before Refresh to clean associations?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 2:35 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
NHibernate doesn't support all cascade styles that Hibernate 3 supports.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 3:09 pm 
Newbie

Joined: Wed Jul 04, 2007 5:31 pm
Posts: 17
Ok, i'll use Evict-Refresh sequence and will wait for support:)

Thanks a lot Sergey!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 18, 2007 2:14 pm 
Newbie

Joined: Wed Jul 04, 2007 5:31 pm
Posts: 17
Unfortunately my problem is still not solved. Please consider following scenario:

I have object X with many-to-one association Y (lazy). Y is mapped
like this:
<many-to-one name="_y" access="field" column="Y_ID" cascade="all"/>.

Originally i have object _x where _x._y.SomeProperty is equal to "original value".
Then i change _x like this:

_x._y.SomeProperty = "new value";
_x._y = _otherY;

After this i want to discard changes made to _x, i.e. i want to refresh _x
so that _x._y.SomeProperty will return to "original value".

After calling this code:
Session.Evict(_x);
Session.Refresh(_x);
_x._y.SomeProperty is equal to "new value"...

So the main question is - how to correctly discard changes made to
persistent object (including all of its associations)? I think this is a very
common scenario, does anybody know how to solve this?


Top
 Profile  
 
 Post subject: Continuance...
PostPosted: Tue Jul 22, 2008 5:13 am 
Newbie

Joined: Tue Jul 22, 2008 5:10 am
Posts: 3
I'm following a similar situation. My object is refreshed, but after the evict, refresh, SaveUpdate does not function. /slapforehead


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