Using Java 1.6, Hibernate 3, and Oracle 10g, I am seeing the following behavior.
When storing a list of objects that include timestamps as members using saveOrUpdateAll, approximately half the time all timestamps being saved appear in the database with one second added. I am explicitly setting the timestamps' seconds field to 0, but sometimes they show up in the DB as 12:00:00 and sometimes as 12:00:01. It is confusing enough that one second is being added, but the intermittent nature of the problem makes it especially baffling. My searches have uncovered discussion of the difference between java.util.Data and java.sql.Timestamp, the perils of using equals to compare the two, etc. but nothing that seems related to the problem I am seeing. Has anyone seen this behavior? Have I overlooked discussion of this problem elsewhere?
More details follow, in case more details will be helpful. If any additional details will be helpful, ask away!
Class pseudo-code:
Code:
class foo {
CustomIdClass fooKey;
java.sql.Timestamp timestamp1;
java.sql.Timestamp timestamp2;
various data fields;
getters+setters;
}
class CustomIdClass {
long barKey;
java.sql.Timestamp timestamp1;
java.sql.Timestamp timestamp2;
getters+setters;
}
Mapping pseudo-code:
Code:
<class name="foo" table="FOO_TABLE">
<composite-id class="CustomIdClass" mapped="true">
<key-many-to-one name="key" column="BAR_PK" lazy="false"/>
<key-property name="timestamp1" column="ONE_TS" type="timestamp" />
<key-property name="timestamp2" column="TWO_TS" type="timestamp" />
</composite-id>
<various properties>
</class>
Table definition:
Code:
Column Name ID Pk Null? Data Type
ONE_TS 1 3 N TIMESTAMP(0)
TWO_TS 2 1 N TIMESTAMP(0)
BAR_PK 3 2 N NUMBER (7)
ETC. 4 Y NUMBER (7,3)