Hibernate version:
2.1.6 on JDK 1.5
Mapping documents:
Code:
<property
name="createdAt"
type="java.util.Date" (or "timestamp", tried both)
update="true"
insert="true"
access="property"
column="created_at"
/>
import java.util.Date;
private Date createdAt;
public Date getCreatedAt()
{
return createdAt;
}
private void setCreatedAt(Date createdAt)
{
this.createdAt = createdAt;
}
Name and version of the database you are using:
MySQL 4.0.18
Problem:
Hibernate populates the above property with a java.sql.Timestamp instead of a java.util.Date. I know Timestamp extends Date, but if you want to use Date.compareTo(Date), you can only compare Date against Date or Timestamp against Timestamp, not Date against Timestamp or the other way around (raises ClassCastException).
You should be consistant throughout your application about the use of java.util.Date or java.sql.Timestamp. I chose to use java.util.Date - how can I force Hibernate to always instantiate java.util.Date?
The strange thing is that this problem seems to have started with JDK 1.5 - on JDK 1.4 I was using type="timestamp" and think I got an java.util.Date (at least I did not get a ClassCastException when comparing dates).
Regards,
Andreas