cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrey Razumovsky <razumovsky.and...@gmail.com>
Subject Re: Cloning a CayenneDataObject
Date Tue, 10 Feb 2009 08:25:38 GMT
Hi Paul,

Do you need to clone only the object's attributes (i.e. fields from one DB
table) or you need to clone related objects too? If first, I'd recommend to
iterate through ObjEntity attributes and write their values to new object.
Tell me if you need a snippet.
If second, since you likely don't want to clone *all* relationships, because
this might result in cloning all database, you should write a clone method
which clones only rels specified in DataObject, e.g.

interface CayenneCloneable {
   public List<String> getClonedRelationships();
}

class Artist extends _Artist implements CayenneCloneable {
  ...
}

//somewhere
public static <T extends CayenneDataObject> T clone(T src) {
  //iterate through obj attributes

  if (T instance of CayenneCloneable) {
     //recursively clone relationships
  }
}

That's how I've done it, and I can search my projects for an example if you
want it

Regards,
Andrey

2009/2/9 Paul Logasa Bogen II <plb@tamu.edu>

> I am writing a web application with Wicket on the front end and Cayenne on
> the back end. When a user clicks "Save As" in my application I want to save
> the current working object with a new key. My suspicion is if I just blank
> out the key and do a context.commitChanges() I will just change the key and
> any other information for the object instead of creating new rows in the
> database. Is this correct? And what is the recommended way to clone or copy
> an object to a new one?
>
> plb
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message