-->
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.  [ 3 posts ] 
Author Message
 Post subject: Help with simple criteria
PostPosted: Tue Jul 22, 2008 1:15 pm 
Newbie

Joined: Wed Sep 06, 2006 8:33 am
Posts: 19
I have a simple question about criteria, any help is welcome.

Imagine this class:

public abstract class Base
{
private int _id;
private int _value1;
}

public class A : Base
{
private int _x;
private int _y;
}
public class B : Base
{
private int _z;
}
public class C : Base
{
private int _w;
private int _h;
}

My mapping is accessing the field... all ok and works fine.. the question is:

I want to create a criteria with specifications by type... sample:

I want all objects from Base, where _value1 is equal to 300... and, if the type of object is 'A', the _x is equal '100', if is 'B', _z is equal to '110' and return this object in one list.

I write one solution: i create many criterias, one for each type and in the end i merge all lists in one, but is not elegant... have any other method to do this with one criteria?

Sorry my bad english and thanks for any help


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 22, 2008 1:59 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Have you tried a criteria on your base type ? I'm doing something similar and it's working fine. Maybe it depends on the inheritance strategy you use. I use table-per-class-hierarchy.

In your case it would look like:

Code:
ICriteria crit = session.CreateCriteria(typeof(Base))
   .Add(Expression.Eq("_value1", 300))
   .Add(Expression.Disjunction()
       .Add(Expression.Eq("_x", 100))
       .Add(Expression.eq("_z", 110))
   .List<Base>();


No guarantees that it's working, but something similar is working for me.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 22, 2008 6:22 pm 
Newbie

Joined: Wed Sep 06, 2006 8:33 am
Posts: 19
tks wolli, it's works!


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