Wednesday, August 30, 2006

datetime becomes date only

This one surfaced again today:

java code says:
object.setEventTime(new Date());

java.util.Date "Allocates a Date object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond."

calls to
object.getEventTime();
give a date that has no time: 2006.08.30 00:00:00

Look at DB, contents are: 2006.08.30, type is an Oracle "Date" which is stored to seconds granularity
http://www-db.stanford.edu/~ullman/fcdb/oracle/or-time.html

Culprit: Hibernate mapping. Use:
<property name="eventTime" column="EVENT_TIME" type="timestamp"/>
instead of
<property name="eventTime" column="EVENT_TIME" type="date">

See
http://www.hibernate.org/hib_docs/v3/api/org/hibernate/type/TimestampType.html

No comments: