Re: Clone an Object and Create New PK

From: Mike Kienenberger (mkienen..laska.net)
Date: Tue Mar 23 2004 - 16:50:53 EST

  • Next message: Steve Wells: "Re: Why is a refetchObject required"

    Bret Gregory <bret.gregor..ccesspointinc.com> wrote:
    > I was wondering if there was an easy way to create duplicate objects with
    > their relationships while creating new auto_generated primary keys.
    >
    > I have a table with a 1:n relationship to itself.
    > So an Object can be related to a bunch of other objects.
    >
    > I would like to clone the parent object and all of its ancestors without
    > having to manually copy all of their different attributes and
    relationships.
    > Does anyone know of an easy way to do this?

    I don't know if there's Cayenne-specific support for cloning objects.

    I know that under WebObjects I did this by creating a new data object,
    copying the source data object's attributes to the new data object using
    generic data object methods, then creating Entity-specific code for
    rebuilding relationships.

    I used a Map of Maps to track created objects so I could assign the proper
    relationships, since all of the objects (many different Entity types) had to
    be created before the relationships could be reset.

    I can give you some specific WebObject code examples of this if you end up
    having to go the same route.
    The API for Cayenne should be similar enough for it to be useful.

    Copying objects without relationships is pretty trivial, but once you have
    to deal with relationships, things get complicated very quickly.

    -Mike



    This archive was generated by hypermail 2.0.0 : Tue Mar 23 2004 - 16:49:26 EST