SQLTemplate generates Date instead of Timestamp?

From: Twan Kogels (twa..wansoft.com)
Date: Tue Oct 12 2004 - 05:27:41 EDT

  • Next message: Julien Vignali: "Cayenne, Oracle and Date-based queries..."

    Hello all,

    I've got a problem with SQLTemplate in relation to java.util.Date /
    java.sql.Timestamp

    I've got a SQLTemplate which executes a custom query. The custom query
    results in a List of objects (Document). The Document object has a field
    named "Date" which is of type TIMESTAMP (mysql), java type is
    java.sql.Timestamp. The modeler generates the following code:

    ========
    public java.sql.Timestamp getDate() {
             return (java.sql.Timestamp)readProperty("date");
         }
    ========

    When i do the SQLTemplate query and call the getDate() function a
    ClassCastException is raised. Java can't cast a java.util.Date to
    java.sql.Timestamp. That's really strange. "Date" is not null and contains
    a normal valid value.

    It gets even more strange. When i do a standard SelectQuery and call the
    getDate() function everything works normal.

    I've added a couple of code lines to getDate() to see what's going wrong:

    ========
    public java.sql.Timestamp getDate() {
           Object o=readProperty("date");
           System.out.println(o.getClass()+" - "+o.toString());
           java.util.Date d=(java.util.Date)o;
           java.sql.Timestamp ts=(java.sql.Timestamp)o; //<-- classcastexception
             return (java.sql.Timestamp)readProperty("date");
         }
    ========

    When using SQLTemplate this prints:
    ========
    class java.util.Date - Tue Oct 12 11:04:57 CEST 2004
    ========

    When using SelectQuery this prints:
    ========
    class java.sql.Timestamp - 2004-10-12 11:04:57.0
    ========

    As you can see for some reason SQLTemplate generates a java.util.Date and
    SelectQuery generates a java.sql.Timestamp.

    How can i "tell" SQLTemplate to generate a java.sql.Timestamp instead of a
    "java.util.Date" (which isn't anywhere in my datamap.xml)?

    Thanks,
    Twan Kogels



    This archive was generated by hypermail 2.0.0 : Tue Oct 12 2004 - 05:24:57 EDT