Hello,
I have a domain class property being a Joda DateTime that gives me an exception when running an integration test against an in memory hsqldb database.
Here is the exception
Code:
Hibernate:
select
this_.id as id69_0_,
this_.version as version69_0_,
this_.address_id as address3_69_0_,
this_.firstname as firstname69_0_,
this_.lastname as lastname69_0_,
this_.company as company69_0_,
this_.email as email69_0_,
this_.fax as fax69_0_,
this_.home_phone as home9_69_0_,
this_.work_phone as work10_69_0_,
this_.mobile_phone as mobile11_69_0_,
this_.password as password69_0_,
this_.password_salt as password13_69_0_,
this_.readable_password as readable14_69_0_,
this_.valid_until as valid15_69_0_,
this_.profile as profile69_0_,
this_.image as image69_0_,
this_.mail_subscribe as mail18_69_0_,
this_.sms_subscribe as sms19_69_0_,
this_.creation_datetime as creation20_69_0_
from
user this_
where
this_.valid_until<>?
and this_.valid_until<?
order by
this_.firstname asc,
this_.lastname asc
23:03:45,230 INFO TransactionalTestExecutionListener:279 - Rolled back transaction after test execution for test context [[TestContext@1d6c336 testClass = UserDaoTest, locations = array<String>['classpath:spring-hibernate.xml', 'classpath:spring-hibernate-dao.xml', 'classpath:spring-data-source.xml'], testInstance = core.dao.UserDaoTest@80669d, testMethod = testFindNotValid@UserDaoTest, testException = java.lang.ClassCastException: java.lang.String cannot be cast to org.joda.time.DateTime]]
The domain class
Code:
import org.joda.time.DateTime;
...
private DateTime validUntil;
public DateTime getValidUntil() {
return this.validUntil;
}
public void setValidUntil(DateTime validUntil) {
this.validUntil = validUntil;
}
The mapping
Code:
<property name="validUntil" type="org.joda.time.contrib.hibernate.PersistentDateTime">
<column name="valid_until" not-null="false" />
</property>
The Dao method
Code:
public List<User> findValidTemporarily(DateTime dateTime) {
Criteria criteria = getSession().createCriteria(User.class);
criteria.add(Restrictions.ne("validUntil", "")).add(Restrictions.ge("validUntil", dateTime)).addOrder(Order.asc("firstname")).addOrder(Order.asc("lastname"));
return criteria.list();
}
And the test
Code:
@Test
public void testFindNotValid() {
user0 = userDao.makePersistent(user0);
user1 = userDao.makePersistent(user1);
DateTime today = new DateTime();
List<User> users = userDao.findNotValid(today.toDateTime());
assertEquals(1, users.size());
assertEquals(email0, users.get(0).getEmail());
}