I noticed that I can run it on the command line in MySQL:
Code:
mysql> select mailaddres0_.id as id83_, mailaddres0_.version as version83_, mailaddres0_.firstname as firstname83_, mailaddres0_.lastname as lastname83_, mailaddres0_.email as email83_, mailaddres0_.comment as comment83_, mailaddres0_.country as country83_, mailaddres0_.subscribe as subscribe83_, mailaddres0_.imported as imported83_, mailaddres0_.creation_datetime as creation10_83_ from mail_address mailaddres0_ where DATE(mailaddres0_.creation_datetime)>='2010-11-01' and DATE(mailaddres0_.creation_datetime)<='2010-11-29';
Empty set (0.02 sec)
Indeed the test works fine with the following Dao method:
Code:
public List<MailAddress> findByCreationDateTime(DateTime fromDateTime, DateTime toDateTime) {
Query query = getSession().createQuery("from MailAddress where DATE(creationDateTime) >= ? and DATE(creationDateTime) <= ? order by firstname, lastname, email");
query.setDate(0, fromDateTime.toDate());
query.setDate(1, toDateTime.toDate());
return query.list();
}
When the test is run in a MySQL environment:
mvn clean test -Pmysql-test
But when the test is run in a HSQLDB environment:
mvn clean test -Pintegration-test
then it fails:
Quote:
Caused by: java.sql.SQLException: Unexpected token: DATE in statement [select mailaddres0_.id as id83_, mailaddres0_.version as version83_, mailaddres0_.firstname as firstname83_, mailaddres0_.lastname as lastname83_, mailaddres0_.email as email83_, mailaddres0_.comment as comment83_, mailaddres0_.country as country83_, mailaddres0_.subscribe as subscribe83_, mailaddres0_.imported as imported83_, mailaddres0_.creation_datetime as creation10_83_ from mail_address mailaddres0_ where DATE(mailaddres0_.creation_datetime)>=? and DATE(mailaddres0_.creation_datetime)<=? order by mailaddres0_.firstname, mailaddres0_.lastname, mailaddres0_.email]
I guess the Hypersonic HSQLDB does not like the DATE() function.
How can I have a statement that runs on any database environment ?
I was hoping the Criteria API would come to the rescue here...