-->
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.  [ 2 posts ] 
Author Message
 Post subject: ISession.Get<T> seems to not work correctly with cachi
PostPosted: Wed Sep 03, 2008 5:39 pm 
Newbie

Joined: Wed Sep 03, 2008 5:00 pm
Posts: 1
I'm using NHibernate 2 and with the typical Hashtable cache provider. I'm noticing a strange thing.

When I query an entity via Session.Get<T> I get an object back that is fully fleshed. If I change a property of that object and NOT call SaveOrUpdate but query the same entity and get another reference back the property that was changed on the first is the same on the second.

pseudo code:

SomeObject obj = Session.Get<SomeObject>(1);

// success
AssertEqual(obj.Description, "foo");

obj.Description = "bar";

SomeObject obj2 = Session.Get<SomeObject>(1);

// this fails b/c some reason the two are equal
AsssertNotEquals(obj.Description, obj2.Description);

The assumption I'm making is that SessionImpl is proxying an interface to the same cached object by key. And b/c I'm using the Hashtable cache provider the memory reference is the same within the heap of the AppDomain.

Is this correct? Does anyone have any clue what is going on here?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2008 2:00 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I don't know a bout NHibernate but this is expected behavior in the Java version of Hibernate. In a single session there is never more than one instance of an entity with a given ID. So, obj and obj2 are actually referring to the same instance. I would be very surprised if the same wasn't true for NHibernate since there is a lengthy discussion about this in the Hibernate docs: http://www.hibernate.org/hib_docs/v3/re ... s-identity


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