Re: Should commitChangesToParent() call pre-persist method?

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue Aug 19 2008 - 06:49:21 EDT

  • Next message: Eric Polino: "QueryChain"

    commitChangesToParent() calls pre-persist on the parent's copy of the
    object, so technically it is called once per object instance. Now I
    agree that the callback mechanism was designed with no concept of
    nested contexts in mind (we cloned it from the JPA spec)... I guess
    once way to address the problem is to check where it is called, and
    skip it either for the child or the parent context:

    void prePersist() {
        if(getObjectContext().getChannel() instanceof ObjectContext) {
             // nested context
             ....
        }
        else {
             // topmost context
             .....
        }
    }

    Andrus

    On Aug 19, 2008, at 8:45 AM, Dave Dombrosky wrote:

    > Should commitChangesToParent() call my pre-persist method?
    >
    > I have coded up a pre-persist listener to set my object's type for
    > cayenne inheritance, and also to create some new objects to fill in
    > required relationships. The problem I am running into is that my
    > pre-persist method gets called twice. Once when i register my object
    > with the child context, and once again when the changes are committed
    > to parent. This causes issues because I my relationships point to
    > unfilled objects, and when I try to commit I get validation errors
    > because of these extra objects.
    >
    > Is this the expected behavior of pre-persist? If so, then where would
    > be a good place to initialize required relationships?
    >
    > -Dave
    >



    This archive was generated by hypermail 2.0.0 : Tue Aug 19 2008 - 06:50:02 EDT