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.  [ 4 posts ] 
Author Message
 Post subject: How to get Simple list of root entities?
PostPosted: Mon Jul 17, 2006 9:27 am 
Beginner
Beginner

Joined: Tue Jan 17, 2006 12:55 pm
Posts: 49
I have a reasonably complex domain model, hence the use of ORM.

In a few places I simply want a simple list of just the root enties in my query. Is there a quick and easy way to do this?

We did try to override the mapping by setting the SetFetchMode but NHibernate seemed to ignore these settings, so for the few instances where we wanted a simple list, we simply went direct to the database with a simple query and built the objects ourselves, with a performance improvement of a factor of 100+!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 17, 2006 10:00 am 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
How is the root related to the children? If the children are represented as collections, then marking the collections as lazy-loaded should help.

Another option, albeit an ugly one, would be to map a second root object without all of the children mapped.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 17, 2006 10:17 am 
Beginner
Beginner

Joined: Tue Jan 17, 2006 12:55 pm
Posts: 49
benhyrman wrote:
How is the root related to the children? If the children are represented as collections, then marking the collections as lazy-loaded should help.


This is what I have been doing.. as I said the real problem is that NHibernate has been known to ignore my SetFetchMode on many occasions and build a large object graph unneccessarily... I still haven't been able to find out why...

Also, this approach requires you to explicitly "switch off" all the collections, which requires you to change the queries each time you add another collection to the root entity.. Now, I'd prefer a technique to specifically load the root entities only without having to worry about the rest of the object graph.

Now, as for the using a different entity with no collections, there is pragmatic and there is outrageously pragmatic! Thanks for the idea anyway!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 17, 2006 10:48 am 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
If you have lazy="true" in your mapping, I assume you've also set every mutator to virtual?

(trivial, but I get stuck on trivial many times myself)


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