views:

33

answers:

2

Hello,

My application consists of two views, list and detail.

Every instance of view has it's own NHibernate session.

When user saves entity from detail view, an event is published to the list view (entity id) after that, list view re-fetches modified entity using it's own session.

In order for list view's session to get fresh version of modified entity I call Session.Clear() method and it works fine, but then I start getting:

Initializing[Core.Domain.Order#0001730]-failed to lazily initialize a collection of role: Core.Domain.Cable.OrderItems, no session or session was closed

What would be proper way to "synchronize" sessions and avoid lazy load exceptions?

Thank You

A: 

Do not use long running sessions. They are not designed to synchronize (that's why you use a database?). Session.Clear() should only be used in exceptional circumstances.

Paco
+1  A: 
Session.Refresh(object);

you may have to call

Session.Evict(object);

then

Session.Refresh(object); 

in some many-to-one situations.

0A0D