View as DB entity and primary key (3M6 and 3B1)

From: Dirk Lattermann (dlat..lqualonde.de)
Date: Fri Dec 11 2009 - 16:40:46 EST

  • Next message: Andrey Razumovsky: "Re: ParseException with EJBQL expression"

    Hello,

    to perform a somewhat complex query, I'm using a database view that
    returns values for the primary key of table A, selecting the rows that
    are interesting. I modeled this view into an db entity dbVA with one
    attribute and one to-one relationship to the table A. The corresponding
    object entity VA doesn't have any attributes, only a to-one relationship
    to the object entity corresponding to table A. VA is marked as
    read-only, and dbVA doesn't have a primary key, as the value referencing
    the pk of table A might appear several times.

    In Cayenne 3M6, this setup worked, but 3B1 complains when performing a
    query on VA:

    Caused by: org.apache.cayenne.CayenneRuntimeException: [v.3.0M6 May 18
    2009 07:49:46] Won't be able to create ObjectId for 'VA'. Reason:
    DbEntity 'dbVA' has no Primary Key defined.
            at
    org.apache.cayenne.access.ObjectResolver.init(ObjectResolver.java:71)
            at
    org.apache.cayenne.access.ObjectResolver.<init>(ObjectResolver.java:57)
            at org.apache.cayenne.access.DataDomainQueryAction
    $ObjectConversionStrategy.toObjects(DataDomainQueryAction.java:589)
            at org.apache.cayenne.access.DataDomainQueryAction
    $SingleObjectConversionStrategy.convert(DataDomainQueryAction.java:624)
            at
    org.apache.cayenne.access.DataDomainQueryAction.interceptObjectConversion(DataDomainQueryAction.java:455)
            at
    org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:126)
            at
    org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:736)
            at
    org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:333)
            at
    org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:96)
            at
    org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1276)
            at
    org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1265)

    I'm puzzled by this, and would be glad if someone could explain to me

    1. Do I really need a pk on my view db entity? Why did this then work
    with 3M6?

    2. Since I'm modelling a db entity for a view, I intended to set the
    read-only property there (which would make a pk unneeded from a DB point
    of view), but this is not possible, only object entities can be set to
    read-only. What's the rational for this?

    3. Is the idea to model a view into a db entity crazy?

    Thank you very much,
    Dirk



    This archive was generated by hypermail 2.0.0 : Fri Dec 11 2009 - 16:41:24 EST