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