-->
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: List instances without derived classes
PostPosted: Tue May 06, 2008 12:03 pm 
Newbie

Joined: Thu Jun 22, 2006 12:51 pm
Posts: 10
I have 2 classes

class A{}
class B:A{}
both mapped to same table with descriminator

when i do
ICriteria criteria = session.CreateCriteria( type );
return criteria.List();

It will return all instances of A and B.


Can i query only A List without subtypes?


Top
 Profile  
 
 Post subject: List instances without derived classes
PostPosted: Tue May 13, 2008 11:52 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi,

If both classes are mapped, then I think it's by design that NHibernate will load all the subclasses when you load the base-type (because in your example B 'is a' A).

The only workaround I can think of is to try something like:
Code:
session
    .CreateCriteria(typeof(A))
    .Add(Expression.Sql("myDiscriminatorColumn = ?", discriminatorValueForClassA))
    .List();


Regards,
Richard


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.