Re: transient objects: NPE on a.setToB(new B())

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Sat Nov 25 2006 - 12:06:17 EST

  • Next message: Tomi NA: "Re: transient objects: NPE on a.setToB(new B())"

    Yeah, at the moment for the relationships to work, objects have to be
    registered with DataContext. In 3.0 we will likely be working on ways
    to "attach" unregistered graphs to the DataContext, but as of now
    this feature is not there yet.

    Andrus

    On Nov 25, 2006, at 10:44 AM, Tomi NA wrote:

    > I'm using (jgoodies) binding as a sync mechanism between my view and
    > model (cayenne objects) so what I basically do is:
    > A a = new A();
    > // bind the model (a) to the UI
    >
    > When I need to replace the initial (empty) model with a new (empty)
    > model or a committed model, I simply set the new model to the new or
    > committed model and the bindings remain in place.
    >
    > However, I now have two beans representing the model and have tried to
    > do the following:
    > A a = new A();
    > B b = new B();
    > a.setToB(b);
    > // bind a and b to the UI
    >
    > The setToB call, however, throws a NPE.
    >
    > It's possible that I wouldn't be facing this problem if I registered
    > the objects with the DataContext, but I'd rather not if there's a way:
    > the above approach worked well so far.
    >
    > I register the objects with the DataContext once their properties have
    > been properly edited and validated and the object itself is added to a
    > list of valid objects. It seemed to make sense to me that I can build
    > an object graph, register it's objects with the DataContext and then
    > simply commit or rollback the changes. It seems that my first
    > assumption was flawed.
    > Could someone please enlighten me on the subject?
    >
    > TIA,
    > t.n.a.
    >



    This archive was generated by hypermail 2.0.0 : Sat Nov 25 2006 - 12:06:45 EST