Hi,
I know there is a lot of mail on the Date nanosecond issue. But I found a strange issue, just wanna know if anyone have found this problem too.
I use a Sybase database. My Pojo have a java.util.Date GeneratedDateTime property mapped on a
datetime row of a mapped table.
In dbVisualiser (under jre1.4 probably) I see that this table contain this data >2004-04-06 07:30:21.303< in this column for a given row. This means 6 April 2004, 7:30:21 + 303 milliseconds.
When I use the JRE1.4 to make a Unit testing, it works as it should.
Code:
// convert util use the SimpleDateFormater to create a Date from a String
Date generatedDateTime = DateConvertUtil.convertStringToDate("2004-04-06 07:30:21.303", "yyyy-MM-dd hh:mm:ss.SSS");
// vo is the Pojo object get from the DAO...
assertEquals(generatedDateTime, vo.getGeneratedDateTime());
But if I set my JRE to 1.3.1 (as my production environment is currenly set) the Unit test fail!
I have this strange error:
Code:
junit.framework.AssertionFailedError: expected:<Tue Apr 06 07:30:21 EDT 2004> but was:<2004-04-06 07:30:21.303>
at junit.framework.Assert.fail(Assert.java:47)
It seems that when using JRE1.3 the milliseconds part is not load from the database!
But in the debug mode, I see that "303" was actually load! But it said that 303 is now the amount of nano seconds, not milliseconds! Is that a bug of com.sybase.jdbc2.tds.SybTimestamp?
From my debugger:
GeneratedDateTime is the value expected from the construction of a Date following this pattern : yyyy-MM-dd hh:mm:ss.SSS. The date is ok.
expected= Date (id=46)
cal= null
fastTime= 1081251021303vo.getGeneratedDateTime() is loaded from the DB. This date miss the milliseconds part!
actual= SybTimestamp (id=166)
cal= null
fastTime= 1081251021000
nanos= 303333333Does anyone knows how to get ride of that?
Mapping of this property:
Code:
<property name="generatedDateTime" type="java.util.Date">
<column name="GeneratedDateTime" scale="23" precision="3"
not-null="false" sql-type="datetime" />
</property>
It seems quite straight foward.
Thanks
Etienne.