-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: SybTimestamp DateType miss Milliseconds in jre1.3.1!
PostPosted: Wed Aug 17, 2005 4:50 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
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= 1081251021303



vo.getGeneratedDateTime() is loaded from the DB. This date miss the milliseconds part!
actual= SybTimestamp (id=166)
cal= null
fastTime= 1081251021000
nanos= 303333333



Does 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.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 4:58 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
In fact the problem is on the other side, Hibernate did load the 303 milliseconds because 303333333 nanoseconds is in fact 303 milliseconds.

But now I dont see why the Date Object I create with the SimpleDateFormat is not equal to 2004-04-06 07:30:21.303...


expected= Date (id=46)
cal= null
fastTime= 1081251021303


Any idea?

Etienne.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 6:41 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 11:06 pm
Posts: 46
Note that Date equals() is based on how many milliseconds since January 1, 1970, 00:00:00 GMT.

_________________
Jason Li
Don't forget to rate:)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 9:46 am 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
Yes, I know that Date is compared in milliseconds. The problem is not directly related to Hibernate (sorry Hibernate Group), but how the comparison is made between 2 dates (Date and SybTimestamp) in 2 JRE:

Between the expected Date "1081251021303 milliseconds" and the actual SybTimestamp date get from Hibenate/Sybase "1081251021000 milliseconds + 303333333 nanoseconds." Theses Date are not compared the same way in 2 JRE.

In IBMJRE 1.3.1 it is not equals, and in SunJRE1.4 it is consider equal!

I am quite confuse here.

If anyone did have this problem it could help me. I will maybe be less strict on the Unit Testing then, because Hibernate is the one who give me the right date.


this is my converter, is the error there?

Code:
   public static Date convertStringToDate(String stringValue, String format) {
      SimpleDateFormat formatter = new SimpleDateFormat(format);
      try {
         return formatter.parse(stringValue);
      } catch (ParseException e) {
         throw new UserTypeParsingRtException(
               "Cannot convert this String to date " + stringValue, e);
      }
   }

Thanks all.

Etienne.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.