Re: Change of primary key - need to update others??

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Mon Nov 29 2004 - 23:31:36 EST

  • Next message: Andrus Adamchik: "Re: Change of primary key - need to update others??"

    Hi Alex,

    Please in the future copy questions to the mailing list (something I am
    doing with this reply)...

    One way is to build a relationship in the modeler, use this
    relationship to retrieve a list of objects to update ... If the related
    objects have category name as a class property, update it manually via
    setCategoryName(..). If not, then things get funky, as ObjectIds that
    hold the object graph together are going to be messed up. This may need
    some experimentation, but the idea is to hold fetched list of related
    objects in memory, then commit the category, and then manually reset
    category on those objects as if the category has changed.

    Andrus

    On Nov 28, 2004, at 9:08 PM, Alex Gunawan Wibowo wrote:
    > Hello there...
    >
    > "but Cayenne
    >> can help you finding
    >> those related objects so that you could do the
    >> update yourself."
    >
    > How can this be achieved??
    >
    >
    > Thx in advance!
    >
    >
    > Best regards,
    >
    >
    > Alex.
    >
    > --- Andrus Adamchik <andru..bjectstyle.org> wrote:
    >
    >> Hi there,
    >>
    >> I think it was mentioned in one of the recent
    >> threads (??), but you'll
    >> be better off defining a "meaningless" integer PK
    >> for category. This
    >> way (1) cayenne will generate it for you, (2) you
    >> can rename category
    >> without breaking any DB references. This of course
    >> assumes that you can
    >> control the schema...
    >>
    >> If you have to stay with current schema, Cayenne
    >> will not automatically
    >> update related tables [after all object identity is
    >> a cornerstone of an
    >> ORM, and here it is being destroyed], but Cayenne
    >> can help you finding
    >> those related objects so that you could do the
    >> update yourself.
    >>
    >> Cheers
    >> Andrus
    >>
    >> On Nov 28, 2004, at 6:31 AM, Alex Gunawan Wibowo
    >> wrote:
    >>> Hello...
    >>>
    >>> I have a question...
    >>> say my database schema is like this:
    >>>
    >>> category: _categoryName_ , status
    >>>
    >>> where categoryName is in String, and it's a
    >> primary
    >>> key.
    >>> Other tables are referring to this "category"
    >> table,
    >>> e.g.: product: _productId_, categoryName.
    >>>
    >>> If i change the categoryName of a record in
    >> "category"
    >>> table, do I need to look for all records in
    >> "product"
    >>> table that has the relationship to the "category"
    >>> table with the old categoryName, and set the new
    >>> categoryName?
    >>> or is cayenne smart enough to handle that in
    >>> background?
    >>>
    >>> Thanks a lot for the help!
    >>>
    >>> Best regards,
    >>>
    >>> Alex Wibowo.
    >>
    >>
    >
    >
    >
    >
    > __________________________________
    > Do you Yahoo!?
    > The all-new My Yahoo! - What will yours do?
    > http://my.yahoo.com
    >



    This archive was generated by hypermail 2.0.0 : Mon Nov 29 2004 - 23:31:44 EST