I am using Hibernate 4 on DB2 v9 with JPA 2’s CriteriaBuilder to build a query on the fly that can filter by date. The relevant part of the predicate is…
criteriaBuilder.greaterThan(myRoot.get(MyEntity_.myDate), aDateValue)
My mapping is pretty straight forward…
@Column(name="MY_DATE")
@Temporal(value = TemporalType.DATE)
public Date getMyDate() {
return myDate;
}
The column on the table is of type DATE. The error I get when I run a query with this restriction is…
org.hibernate.exception.DataException: DB2 SQL Error: SQLCODE=-181, SQLSTATE=22007
If I take the generated SQL and run it in a stand alone SQL editor, it runs fines. I have tried changing to TemporalType.TIMESTAMP with no luck. I have double-checked that the bind input is valid at runtime as well.
Turns out that if
aDateValueis of typejava.sql.Daterather thanjava.util.Datethe error goes away.