Re: working with views

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue Apr 12 2005 - 21:57:11 EDT

  • Next message: Jürgen Saar: "Re: ExpressionFactory problems"

    On Apr 12, 2005, at 3:43 PM, tnaki..ofthome.net wrote:

    > When I reverse engineer the database schema, a view is basically
    > represented the same way a table would be. However, my validation
    > failed repeatedly becouse my views lack a primary key - which,
    > considering the nature of the information I needed, is as it should
    > be: they just provide raw data. The problem boils down to no primary
    > key and no root object - I have no idea how to cope with such data
    > using cayenne.

    > I had hoped SQLTemplate would do the trick, but it needs a root object
    > and I don't have one.

    It will. If you fetch "data rows" instead of objects, root is simply
    used to determine which DataNode to connect to. So it can be any class
    from the same DataMap. If you fetch DataObjects, then well.. root is
    naturally the class that you fetch (so you do have one).

    > Anyway, what I did was I introduced primary keys into the views by
    > marking whichever column contained unique values as primary keys.

    This is an ok solution. I use it often for the legacy schemas whose
    creators didn't bother to ensure data integrity.

    > Where I had no such columns, I made artificial ones.

    Now this looks scary... If your view rows don't have identity (i.e. you
    can't use even a "synthetic" primary key over the existing columns),
    use data rows. This is the best solution for such type of data. It is
    read-only anyway.

    http://objectstyle.org/cayenne/api/cayenne/org/objectstyle/cayenne/
    query/SelectQuery.html#setFetchingDataRows(boolean)

    http://objectstyle.org/cayenne/userguide/perform/data-rows.html

    Andrus



    This archive was generated by hypermail 2.0.0 : Tue Apr 12 2005 - 21:57:14 EDT