Re: Composite objects

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue Nov 09 2004 - 23:21:08 EST

  • Next message: Twan Kogels: "RE: Cayenne returning a resultset?"

    Hi Darek,

    There is a number of issues here. Some can be solved within current
    Cayenne design, some - with custom wrapping of DataObjects, and some
    will probably require enhancements to the Cayenne core. So lets see
    what we have...

    On Nov 8, 2004, at 11:02 PM, Derek Rendall wrote:
    > The first is basicaly the classic Address within Party where we have
    > an object that wraps several attributes of the domain object in order
    > to provide certain standardised functionality. Other examples include
    > cases where we have several related attributes dealing with taxation
    > etc. In this case we do not need to create these objects outside of
    > the context of their parent.

    For this you can still map your DataObjects to the table structure, but
    create wrapper methods on the "parent" object. In the future we will
    allow "flattened" attributes just like we do allow flattened
    relationships now. I believe a part of the backend for flattened
    attributes is already there, but undocumented and untested (it was done
    some time ago by Andriy for a specific case, but we never made it
    generic and official).

    > The other case involves a class we created a class that wraps a
    > BigDecimal. In our current data layer we translate attributes that are
    > instances of this object to/from a BigDecimal in the database. We have
    > a lot of complex code that uses this wrapping class, and I want to
    > change things as little as possible. In this case, we do need to be
    > able to create this object outside of its parent and assign it to an
    > attribute on the parent.
    >
    > Is there a way to do either (similar to Hibernates User
    > Objects/Types?), particularly the second case? If not, is such
    > functionality planned anytime soon? If the answer is still no, what
    > would be the best approach to try and implement such behaviour?

    Yes - ExtendedTypes in Cayenne do exactly that...
    http://objectstyle.org/cayenne/api/cayenne/org/objectstyle/cayenne/
    access/types/package-summary.html. There are some limitations related
    to the use of inheritance
    (http://objectstyle.org/jira/secure/ViewIssue.jspa?key=CAY-207), and
    also use of data rows, but normal object queries and relationships
    should work just fine.

    > Also, while Im writing an email to the list: I noticed that
    > BigDecimals with a scale can get their scaled values set when pushing
    > to the database, but the object does not reflect this. For example, if
    > I have a scale of 2 for a BigDecimal and I set the attribute to
    > "0.155" then "0.15" is persisted, but the object still states "0.155".
    > DB2 throws an exception if the scale is wrong, so this behaviour stops
    > the exception happening (which I tend to agree with from a practical
    > point of view), but I want the object and database data to match after
    > saving. I had thought of changing the java template so that
    > BigDecimals are checked for scale in the set method. Is there a better
    > alternative? Could this be thought of as a bug, and I need to raise a
    > Jira issue?

    What is the precision set for DB column (and DbAttribute in the
    modeler)? Could it be that it is lost because of the column definition
    or mapping? If this is not the case, please open a bug report.

    Thanks
    Andrus



    This archive was generated by hypermail 2.0.0 : Tue Nov 09 2004 - 23:21:13 EST