-->
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: Conditional Search using Criteria and Expression
PostPosted: Tue May 04, 2004 11:25 am 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
I am using Hibernate 2.1.2.

I have a LoginHistory object that has a loginTimestamp and logoutTimestamp and am trying to get all LoginHistory objects that fall between a specific limit.

The problem is that everyone that logs in doesn't necessarily log out. So I have to do the following in HQL.

Code:
SELECT loginhistory
FROM LoginHistory loginHistory
WHERE loginHistory.loginStamp > :loginStamp
AND (
     loginHistory.logoutStamp < :logoutStamp
  OR loginHistory.logoutStamp IS NULL
    )
ORDER BY loginHistory.loginHistoryId DESC


Is there any way to accomplish this using Criteria and Expression objects? I can't seem to figure out the Expression.or() method.

I tried working with the Criteria object and this is as far as I got.

Code:
Criteria criteria = hibernateSession.createCriteria(LoginHistory.class);
criteria.add(Expression.gt("loginStamp", requestLoginHistory.getLoginStamp()));
criteria.add(Expression.lt("logoutStamp", requestLoginHistory.getLogoutStamp()));


But I can't figure out how to get the OR conditional for the logoutStamp to work. Any help is appreciated.

TIA


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 11:32 am 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Use a disjunction. (Section 12.2 in the manual has an example.)


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 11:36 am 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
Thank you for the prompt reply. Appreciate the help.


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.