Re: Stored Procedure Date casting problem...

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Apr 07 2005 - 22:57:03 EDT

  • Next message: Jürgen Saar: "RE: Testing ExpressionFactory for null values"

    Yeah, ProcedureQueries are unfortunately lacking in this respect. I
    opened a number of Jira issues to address it (notable this one -
    http://objectstyle.org/jira/secure/ViewIssue.jspa?key=CAY-148 ). The
    goal is to make them as flexible as SQLTemplate queries.

    Regarding your specific case:

    > public java.sql.Date getDate() {
    > return (java.sql.Date)readProperty("date");
    > }

    I suggest simply mapping your DataObject "date" property as
    java.util.Date. You won't sacrifice any functionality if you do that.

    Andrus

    On Apr 6, 2005, at 1:54 PM, Michal Kozlowski wrote:

    > Hi everyone,
    > I'm loving the new SQL Server generatePK feature rith the jTDS driver,
    > works awesome.
    >
    > Now my problem is I create a stored procedure that I want to generate
    > a data object from, the stored procedure is in the modeler, and I also
    > generated a stored procedure query that would allow me to fetch data
    > objects. Now the data object that I'm getting has a sql.Date
    > attribute which works if I just do a Select Query using cayenne like
    > so...
    >
    > Expression qualifier = ExpressionFactory.matchDbExp("ProjectId",
    > "Z00451");
    > qualifier =
    > qualifier.andExp(ExpressionFactory.matchDbExp("UserId", "NGO001"));
    > qualifier =
    > qualifier.andExp(ExpressionFactory.matchDbExp("UnitId", "020"));
    >
    > SelectQuery query = new SelectQuery(ActualConnected.class,
    > qualifier);
    > List actuals = getDataContext().performQuery(query);
    > return actuals;
    >
    > When I do the same thing with a stored procedure I get an error from a
    > cast that is trying to cast a util.Date to sql.Date which cannot be
    > done. Is there any way to prevent this cast from happening
    > automatically?
    >
    > ProcedureQuery query = (ProcedureQuery)
    > getDataContext().getEntityResolver().lookupQuery("getUserActualsQuery")
    > ;
    > query.addParameter(..rojectID","Z00451");
    > query.addParameter(..serID", "NGO001");
    > query.addParameter(..nitID", "020");
    > return getDataContext().performQuery(query);
    >
    > The error happens here in the data object that is trying to be read ...
    >
    > public java.sql.Date getDate() {
    > return (java.sql.Date)readProperty("date");
    > }
    >
    > Thanks for any information to get this working, I'm wondering if there
    > is any way to prevent the stored procedure result from being cast to a
    > util.Date and make it go into a sql.Date object
    >
    > Cheers
    > Mike
    >
    > Developer/Database Administrator
    > IMV Projects Inc.
    > (403) 770-7552
    >
    > It is a painful thing
    > To look at your own trouble and know
    > That you yourself and no one else has made it
    > - Sophocles, Ajax
    >



    This archive was generated by hypermail 2.0.0 : Thu Apr 07 2005 - 22:57:07 EDT