Re: SelectQuery with object parameter

From: Gili (cowwo..bs.darktech.org)
Date: Wed Sep 07 2005 - 01:42:30 EDT

  • Next message: Gili: "saveOrUpdate"

            Sorry for not replying sooner (I was out most of today)... Mike and I
    tracked this down and it was due to user-error. I have two classes with
    identical names and their package names are almost identical.

            I have desktopbeautifier.server.cayenne.DefaultImage and
    desktopbeautifier.server.cayenne.generated.DefaultImage. The former is a
    wrapper for the latter. The latter is a Cayenne DataObject. Anyway what
    was going on is that I was mistakenly passing the wrapper object into
    the query instead of the underlying DataObject.

            Thanks again Mike for helping catch this :)

    Gili

    Gentry, Michael (Contractor) wrote:
    > Cayenne does need and use the PK when your query parameter is a
    > CayenneDataObject subclass (instead of a string/etc). Let me go out on
    > a limb and ask: does your object have multiple PKs? If not, could you
    > post some of your query code?
    >
    > -----Original Message-----
    > From: Gili [mailto:cowwo..bs.darktech.org]
    > Sent: Tuesday, September 06, 2005 1:31 PM
    > To: cayenne-use..bjectstyle.org
    > Subject: Re: SelectQuery with object parameter
    >
    >
    >
    > I increased the logging level...
    >
    > 13:29:25,516 INFO QueryLogger:421 - --- will run 1 query.
    > 13:29:25,516 INFO QueryLogger:377 - --- transaction started.
    > 13:29:25,531 INFO QueryLogger:315 - SELECT t0.clazz, t0.dataDigest,
    > t0.id, t0.contentType, t0.data, t0.provider, t0.specification, t0.theme
    > FROM image t0 WHERE (t0.theme = ?) AND (t0.clazz = ?) [bind:
    > [desktopbeautifier.server.cayenne.DefaultTheme: Theme[id=1, name=null,
    > childrenCount=0]], 'desktopbeautifier.server.database.DefaultImage'] -
    > prepared in 15 ms.
    > 13:29:25,547 INFO QueryLogger:404 - *** error.
    >
    > Looks to me like Cayenne is expecting the Theme's primary key,
    > and
    > instead it's getting an entire DefaultTheme object. Not sure how to fix
    > that though...
    >
    > Gili
    >
    > Gentry, Michael (Contractor) wrote:
    >
    >>Short answer, yes, you can pass a CayenneDataObject (subclass) as a
    >>query parameter. There's not enough information there for me (at
    >
    > least)
    >
    >>to tell what the issue might be.
    >>
    >>
    >>-----Original Message-----
    >>From: Gili [mailto:cowwo..bs.darktech.org]
    >>Sent: Tuesday, September 06, 2005 1:19 PM
    >>To: cayenne-use..bjectstyle.org
    >>Subject: SelectQuery with object parameter
    >>
    >>
    >>Hi,
    >>
    >> I have a SelectQuery with a root of "DefaultImage", and
    >>qualifier of
    >>"theme = $theme". In my Java code I bind "theme" to a DefaultTheme,
    >>which is a DataObject. Then when I try issueing the query I get this
    >>exception:
    >>
    >>java.sql.SQLException: Cannot convert class
    >>desktopbeautifier.server.cayenne.DefaultTheme to SQL type requested
    >
    > due
    >
    >>to java.lang.ClassCastException -
    >>desktopbeautifier.server.cayenne.DefaultTheme
    >>
    >> The closest discussion I could find is
    >>
    >
    > http://www.objectstyle.org/cayenne/lists/cayenne-user/2002/09/0009.html
    >
    >>but it doesn't look like anyone ever answered it. Am I doing something
    >
    >
    >>wrong? Shouldn't I be able to pass a DataObject as a query parameter?
    >>
    >>Thank you,
    >>Gili
    >
    >

    -- 
    http://www.desktopbeautifier.com/
    



    This archive was generated by hypermail 2.0.0 : Wed Sep 07 2005 - 01:42:33 EDT