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.  [ 1 post ] 
Author Message
 Post subject: Problems querying over collection with criteria API
PostPosted: Sun Oct 09, 2011 7:07 am 

Joined: Thu Sep 01, 2011 6:41 am
Posts: 3
Hi there,

here is my latest problem - I hope anyone can help me - thx a lot :) :

I made a class called 'Employee' :
class Employee {
public virtual ISet<HolidayTime> holidayTimes {get;set;}


As you can see, an employee may also have holiday - and so I need another class calles 'HolidayTime' :

class HolidayTime {

public virtual DateTime from;
public virtual DateTime until;


That's it so far. Each employee can have several periods of time when he is not available.

What I tried is to get all employees from database, which are not in holiday today.
So I tried sth. like this:

ICriteria criteria = session.CreateCriteria<Employee>();
criteria = criteria.CreateAlias("HolidayTime", "times");
DateTime today = DateTime.Today;
Disjunction dis = Expression.Disjunction();
dis.Add(Expression.Lt("times.until", today));
dis.Add(Expression.Gt("times.from", today));

IList<Employee> myList=criteria.SetResultTransformer(new DistinctRootEntityResultTransformer()).List<Employee>();

Now lets say today's is 10/09/2011 (mm/dd/yyyy).
Our employee is on holiday from 10/09/2011 until 10/20/2011.

If I start my search, this employee won't be found. Great - that is want I wanted.
BUT: Now i add another holiday period: from 10/01/2011 until 10/08/2011.

So now we have one time period which is valid for my search and one which is not. The problem is, that my search now gives out that employee, but as you can see: that employee is in holiday today :)

What have I done wrong?

Thanks for you help.


Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.