Refreshing entity throws Exception

133 views
Skip to first unread message

Maximilian Csuk

unread,
Jan 30, 2010, 11:45:30 AM1/30/10
to nhusers
Hi there,

I am trying to use Session.Refresh() to rollback changes made to an
entity in memory. The entity has a lazy loaded one-to-many association/
collection to other entities (cascade is all-delete-orphans).

When I add an entity to the collection and call Refresh(), it gives me
this NHibernate exception:
this instance does not yet exist as a row in the database

As I see it, "instance" refers to the added entity, which is obviously
not persistent in the database. However, I read here (http://
groups.google.com/group/nhibernate-development/browse_thread/thread/
53aa292a0e451c4d?fwc=1), that refreshing also works on associations.
Is that not true for added (or removed) entities?

Is Refresh even the right tool for the job?

Thanks for your time.

Fabio Maulo

unread,
Jan 30, 2010, 11:51:19 AM1/30/10
to nhu...@googlegroups.com
I think we having a opened issue about this matter.

2010/1/30 Maximilian Csuk <maximil...@gmx.at>

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.




--
Fabio Maulo

Maximilian Csuk

unread,
Jan 31, 2010, 6:34:15 AM1/31/10
to nhusers
Thanks!

Is there a bugtracker where I can monitor this issue? What would you
suggest as a work-around? For added entities, I could loop through the
collection and remove all which have no DB-identifier. But for remoed
entities?

Regards,

On 30 Jan., 17:51, Fabio Maulo <fabioma...@gmail.com> wrote:
> I think we having a opened issue about this matter.
>

> 2010/1/30 Maximilian Csuk <maximilian.c...@gmx.at>


>
>
>
> > Hi there,
>
> > I am trying to use Session.Refresh() to rollback changes made to an
> > entity in memory. The entity has a lazy loaded one-to-many association/
> > collection to other entities (cascade is all-delete-orphans).
>
> > When I add an entity to the collection and call Refresh(), it gives me
> > this NHibernate exception:
> > this instance does not yet exist as a row in the database
>
> > As I see it, "instance" refers to the added entity, which is obviously
> > not persistent in the database. However, I read here (http://
> > groups.google.com/group/nhibernate-development/browse_thread/thread/
> > 53aa292a0e451c4d?fwc=1), that refreshing also works on associations.
> > Is that not true for added (or removed) entities?
>
> > Is Refresh even the right tool for the job?
>
> > Thanks for your time.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to nhu...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > nhusers+u...@googlegroups.com<nhusers%2Bunsu...@googlegroups.com>

Fabio Maulo

unread,
Jan 31, 2010, 8:31:20 AM1/31/10
to nhu...@googlegroups.com
As workaround :
session.Evict(entity);
session.Get<TEntity>(id);

2010/1/31 Maximilian Csuk <maximil...@gmx.at>
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.




--
Fabio Maulo

Maximilian Csuk

unread,
Feb 1, 2010, 2:12:24 PM2/1/10
to nhusers
Thanks, that partially works. Unfortunately, when I call these instead
of Refresh, Session.IsDirty() always returns true afterwards. Even
when the entity I refresh was the only one changed. I needed to
replace Evict with Clear in order to get the session clean again. Is
this expected behaviour? I would find it more logical if an evict
could also set a session back to it's clean state again.


On Jan 31, 2:31 pm, Fabio Maulo <fabioma...@gmail.com> wrote:
> As workaround :
> session.Evict(entity);
> session.Get<TEntity>(id);
>

> 2010/1/31 Maximilian Csuk <maximilian.c...@gmx.at>

> > <nhusers%2Bunsu...@googlegroups.com<nhusers%252Buns...@googlegroups.com>

Reply all
Reply to author
Forward
0 new messages