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.  [ 8 posts ] 
Author Message
 Post subject: ISession.List() executes inserts updates and deletes
PostPosted: Mon Feb 11, 2008 5:00 am 
Newbie

Joined: Mon Feb 11, 2008 4:50 am
Posts: 6
I have a fairly large NHibernate based project, to which some new relationships have been added. since then, the time it took to retrieve a list of instances of some specific types has increased hugely. Before the change it was 250 milliseconds tops, now it's pushing 4 seconds.
I ran an SQL profiler trace, and it turns out NHibernate is deleting records and inserting them again a little later, while in between it's updating foreign keys to NULL, and updating them back again to their original value afterwards.
Here's the kicker: I'm using a single class projection to make sure no objects of related classes need to be loaded, but NHibernate does not seem to care.

Does anyone know what I'm doing wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 12, 2008 5:26 am 
Newbie

Joined: Mon Feb 11, 2008 4:50 am
Posts: 6
aaaaand we're done!

Had to debug the NHibernate DLL to figure this one out. Turns out, NHibernate thought I had made in-memory changes, so before I retrieved the the data, the session needed to be flushed.
But since I don't care about changing data (it's a reporting application, for which I am VERY glad at the moment) , I can just set the ISession.FlushMode to FlushMode.Never, and I'm done!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 12, 2008 6:28 pm 
Regular
Regular

Joined: Tue Dec 25, 2007 3:41 pm
Posts: 57
Location: Argentina
Yes, you're right, that how NHibernate works.

Another tip is create DTO classes (for view purpose) and mark the map as mutable="false", then no updates go to be executed.

Best regards

_________________
Dario Quintana


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 13, 2008 3:29 am 
Newbie

Joined: Mon Feb 11, 2008 4:50 am
Posts: 6
darioquintana wrote:
Yes, you're right, that how NHibernate works.

Another tip is create DTO classes (for view purpose) and mark the map as mutable="false", then no updates go to be executed.

Best regards


That's a great tip, I will keep it in mind, thank you.
One thing I still don't know for sure is why NHibernate was so sure I changed data when I really didn't.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 13, 2008 5:49 am 
Regular
Regular

Joined: Tue Dec 25, 2007 3:41 pm
Posts: 57
Location: Argentina
Believe it, if NHibernate saw the data is changed, the data is changed.

Take a look on this, could be your problem too:
http://www.ayende.com/Blog/archive/2007 ... ssues.aspx

Best regards

_________________
Dario Quintana


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 13, 2008 6:01 am 
Newbie

Joined: Mon Feb 11, 2008 4:50 am
Posts: 6
The thing is, in this application I only use projected queries, the results of which are transformed into my own DTO's. (performance issues, my app is an addition to an original app, don't ask ;) )
how can nhibernate possibly know (or care for that matter) if my DTO's are changed?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 13, 2008 7:39 am 
Regular
Regular

Joined: Tue Dec 25, 2007 3:41 pm
Posts: 57
Location: Argentina
NHibernate keep track about the persistent objects (associated to a session). And it looks if the object is dirty or not.

Why you need the DTO keep track of the changes on the DTO?

By definition the DTOs are expected to be immutables, and you must do it by code (readonly objects) and by NHibernate (mutable="false").

_________________
Dario Quintana


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 13, 2008 8:01 am 
Newbie

Joined: Mon Feb 11, 2008 4:50 am
Posts: 6
darioquintana wrote:
NHibernate keep track about the persistent objects (associated to a session). And it looks if the object is dirty or not.

Why you need the DTO keep track of the changes on the DTO?

By definition the DTOs are expected to be immutables, and you must do it by code (readonly objects) and by NHibernate (mutable="false").


my point exactly. My DTO's aren't mapped in hbm's. my DTO's are a subset of persistent objects through projection and resulttransformers, and are therefore not persistent!


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