Re: how to use SQLTemplate

From: Bryan Lewis (brya..aine.rr.com)
Date: Sat Sep 18 2004 - 14:41:08 EDT

  • Next message: Bryan Lewis: "suggestion: CayenneDataObject equals()"

    I was out of town for a week and just now got back to this. Your second
    suggestion was correct. The column names in my model (DataMap) didn't
    exactly match what Oracle was returning in upper/lower case.

    A quick experiment with the #result directive verified it. The
    following line specifies that the COMPANY_ID values returned by Oracle
    correspond to the DbEntity's Company_ID attribute:

       sql = "SELECT #result('COMPANY_ID' 'Integer' 'Company_ID') from Company";

    That gave me a list of objects that at least had the correct Company_ID
    (rather than all nulls) so I knew I was on the right track. Rather than
    write a lot of #result macros, I upper-cased all the db attribute names
    in my DataMap. After that the simple "SELECT *" sql worked fine.

    Thanks!

    Andrus Adamchik wrote:
    > Well, as the COMPANY_ID is null, that's not even valid faults... A few
    > things to check before looking any deeper:
    >
    > 1. Is Company mapped as an ObjEntity, with an underlying DbEntity. This
    > is a requirement in the current version to turn result into DataObjects
    > (in the future versions we will support mapping of ObjEntity to a
    > SQLTemplate bypassing DbEntity, and mapping an arbitrary Java class to
    > a SQLTemplate)
    >
    > 2. Try replacing "SELECT *" with a specific list of columns, creating
    > column aliases using "#result" directive (see 7.7.2 -
    > http://objectstyle.org/cayenne/userguide/fetch/sqltemplate-
    > scripting.html). This may be needed on some databases due to possible
    > column name capitalization issues (e.g. you can have a DbAttribute
    > called "Company_ID", while ResultSet column as returned by the DB by
    > default may be called "company_id", or "COMPANY_ID", so explicit column
    > naming is needed).
    >
    > Andrus
    >
    >
    >
    > On Sep 9, 2004, at 1:33 PM, Gentry, Michael wrote:
    >
    >> I've not used SQLTemplate, but it looks to me like you have a List of
    >> faults. Trying to do something with those 10 Company objects will
    >> probably fault them in from the database.
    >>
    >> /dev/mrg
    >>
    >>
    >> -----Original Message-----
    >> From: news [mailto:new..ea.gmane.org] On Behalf Of Bryan Lewis
    >> Sent: Thursday, September 09, 2004 12:07 PM
    >> To: cayenne-use..bjectstyle.org
    >> Subject: how to use SQLTemplate
    >>
    >>
    >> I must be missing something about SQLTemplate. I updated to version
    >> 1.1B2 and tried a simple example like the one in the User Guide:
    >>
    >> String sql = "SELECT * FROM COMPANY";
    >> SQLTemplate query = new SQLTemplate(Company.class, sql, true);
    >> query.setFetchLimit(10);
    >> List companies = dataContext.performQuery(query);
    >> log.debug("companies = " + companies);
    >>
    >> I get a list of 10 empty objects.
    >>
    >> companies = [{[]<oid: model.Company: <Company_ID: null>; state: hollow>}
    >> , {[]<oid: model.Company: <Company_ID: null>; state:
    >> hollow>}
    >> ...
    >>
    >> I see that other people are using SQLTemplate; what am I missing?



    This archive was generated by hypermail 2.0.0 : Sat Sep 18 2004 - 14:41:18 EDT