Re: DATETIME type in mysql?

From: Mike Kienenberger (
Date: Fri Oct 15 2004 - 12:26:19 EDT

  • Next message: Mike Kienenberger: "Re: DATETIME type in mysql?"

    Twan Kogels <> wrote:
    > Thanks for the tip, i'm now using java.sql.Timestamp which seems to be a
    > subclass of java.util.Date. That's also working good, but i'm going to try

    > java.util.Date next.

    I also use java.util.Date to represent both my TIMESTAMP and my DATE values.
     My personal belief is that the java.sql* types should not be used in a
    cayenne application, only in the cayenne framework itself. Instead, you
    should try to use the "standard" java types whenever possible.

    java.sql.Timestamp is only a subclass of java.util.Date in implementation
    (see the API notes), so be careful when using it not to try to use it as a
    Date directly.
    Note: This type is a composite of a java.util.Date and a separate
    nanoseconds value. Only integral seconds are stored in the java.util.Date
    component. The fractional seconds - the nanos - are separate. The getTime
    method will return only integral seconds. If a time value that includes the
    fractional seconds is desired, you must convert nanos to milliseconds
    (nanos/1000000) and add this to the getTime value. The
    Timestamp.equals(Object) method never returns true when passed a value of
    type java.util.Date because the nanos component of a date is unknown. As a
    result, the Timestamp.equals(Object) method is not symmetric with respect to
    the java.util.Date.equals(Object) method. Also, the hashcode method uses the
    underlying java.util.Data implementation and therefore does not include
    nanos in its computation. Due to the differences between the Timestamp class
    and the java.util.Date class mentioned above, it is recommended that code
    not view Timestamp values generically as an instance of java.util.Date. The
    inheritance relationship between Timestamp and java.util.Date really denotes
    implementation inheritance, and not type inheritance.

    This archive was generated by hypermail 2.0.0 : Fri Oct 15 2004 - 12:25:17 EDT