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: Session.Evict not removing object after SetResultTransformer
PostPosted: Wed Sep 05, 2007 12:26 pm 
Newbie

Joined: Wed Sep 05, 2007 12:22 pm
Posts: 8
I’m using the following code to support a legacy view that contains an object

Code:
sql = string.Format(sql, EQUIPMENT_INSTALLATION_SELECT);
query.SetResultTransformer(NHibernate.Transform.Transformers.AliasToBean(typeof(EquipmentInstallation)));


However, when the session.Flush() is called the session is detecting the objects and tries to run an update (which fails as the view cannot be updated).

I have tried evicting the objects and have even tried evicting the object type from the session factory but still nhibernate tries to run an update.

I have checked the logs and also the objects and nothing has been changed so I am guessing that using the SetResultTransformer is in some way causing this to happen.

Any advice would be great


Top
 Profile  
 
 Post subject: Re: Session.Evict not removing object after SetResultTransfo
PostPosted: Thu Sep 13, 2007 8:27 pm 
Regular
Regular

Joined: Fri Jan 20, 2006 7:45 pm
Posts: 97
Location: San Antonio, TX
russuk wrote:
I’m using the following code to support a legacy view that contains an object

Code:
sql = string.Format(sql, EQUIPMENT_INSTALLATION_SELECT);
query.SetResultTransformer(NHibernate.Transform.Transformers.AliasToBean(typeof(EquipmentInstallation)));



I have checked the logs and also the objects and nothing has been changed so I am guessing that using the SetResultTransformer is in some way causing this to happen.

Any advice would be great


I'm not sure about SetResultTransformer, it should return an unmanaged entity and would therefore not be in the cache to flush. If the entity you are querying for is mapped I would think that it would be managed. IF the type you are loading is unmanaged, I would think you'd need SetResultTransformer with AliasToBean along with metadata to help NHibernate with the mapping (like Projections with ICriteria). Again, I'm not sure.

It certainly sounds as if you have the queried entities in the cache and I can't help but wonder if you have a mapping file defined for the class and are using SetResultTransformer to populate a managed entity. If this was the case then I'd guess that NHibernate config knows about your class and is caching the result of your query, in which case subsequent flushes would attempt and update. These are only guesses though.

I do understand that you are reading from a view, so would want a read only context. I know a simpler way to approach this.

I would open a separate session for the call to the view and set
newSession.FlushMode = FlushMode.Never;

When you open this new session you can pass the connection from the current session into the OpenSession method.
ISession newSession = sessionFactory.OpenSession(currentSession.Connection);

Once you query the view and get your results, call newSession.Dispose();
At this point your results are no longer associated with a session and you haven't done any Flush()s.

Hope that helps.


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.