Re: SQLTemplate generates Date instead of Timestamp?

From: Twan Kogels (twa..wansoft.com)
Date: Wed Oct 13 2004 - 04:00:19 EDT

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

    Hello Andrus,

    Thanks, that was indeed the solution.

    After i read your reply i tryed:
    #result('B.date' 'java.sql.Timestamp')
    but that caused a null pointer exception. After a bit of reading at the
    given page i tryed:
    #result('B.date' 'java.sql.Timestamp' 'date')
    and that worked perfectly!

    It's strange i've never saw that help page, next time i will double check
    the docs ;-)

    Cheers,
    Twan

    At 06:00 13-10-2004, you wrote:
    >Hi Twan,
    >
    >You can control the exact Class of each column returned by SQLTemplate
    >by using a "#result(..)" directive -
    >http://objectstyle.org/cayenne/userguide/fetch/sqltemplate- scripting.html
    >. I can't comment further what's going on in you case,
    >as you do not show the script you use for SQLTemplate, but something
    >like #result('DATE' 'java.sql.Timetsamp') for a given column should
    >produce the correct value.
    >
    >Andrus
    >
    >
    >On Oct 12, 2004, at 5:27 AM, Twan Kogels wrote:
    >
    >>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 : Wed Oct 13 2004 - 03:57:55 EDT