kork2 wrote:
hi, i have an application where i need that calling session.Get(id) will always retun the same object istance.
I wouldn't normally call session.Get(id) multiple times for retreiving the same object. Even so, I think this would work since sessions define object identity scope. In my programming, however, I'd call it once then keep a reference to the object it returns. As long as you have the same session open, any changes made can be presisted back to the database by calling session.Flush(). If you open a new session then you can call session.Update(obj) which reattaches it.
greenmtboy wrote:
Keeping the same ISession instance active (a bad idea anyway) won't guarantee that calling Get will always return the same instance of an object, that depends on the caching strategy employed. If you really want to do this, take a close look at NHibernate's second level caching.
As far as I understand, keeping the same session instance open
will guarantee object identity (pls correct me if I'm wrong). And from what I've read about NH's second-level caching (never used it myself), objects are stored
by value, so this wouldn't fit kork2's requirement.