Re: random behaviour in Cayenne?

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Aug 16 2006 - 10:16:02 EDT

  • Next message: Øyvind Harboe: "Is andExp supported on Scalar booleans?"

    Hi Hans,

    [your address doesn't seem to be subscribed to the list, so be aware
    that you can miss list-only responses]

    Yes, relationships won't probably get copied the way you expect them.
    IIRC someone posted some examples before on how to clone a
    DataObject. In any event it should be fairly easy to do in a generic
    fashion by obtaining an ObjEntity and using DataObject.writeProperty
    () for simple properties:

    ObjEntity e = ctx.getEntityResolver().lookupObjEntity
    (AiAboangebot.class);
    // iterate through entity attributes and use src.readProperty()/
    target.writeProperty()
    // iterate through entity relationships and use src.readProperty/
    target.setToOneTarget()/target.addToManyTarget() for to-one and to-
    many relationships.

    Andrus

    On Aug 16, 2006, at 9:45 AM, Hans Schmidt wrote:

    > Hi,
    >
    > I am using Cayenne 1.2 final release and the following code:
    >
    > public AiAboangebot copyToNewAngebot(AiAboangebot toCopy) {
    > ctx.commitChanges();
    > List ur = new ArrayList();
    > Integer nextId = getNextId(toCopy);
    > AiAboangebot cop =(AiAboangebot)ctx.createAndRegisterNewObject
    > (AiAboangebot.class);
    > ur.add(cop);
    > BeanUtils.copyProperties(toCopy,cop);
    > ctx.unregisterObjects(ur);
    > cop.setId(nextId);
    > ctx.registerNewObject(cop);
    > ctx.commitChanges();
    > return cop;
    > }
    >
    > the purpose of the code is to copy an existing db-row, assign a new
    > id and edit it.
    > the code sometimes works but sometimes not.
    >
    > It seems the relations are sometimes broken so that the generated
    > SQL tries to insert NULL values into non-nullable columns.
    >
    > any help would be greatly appreciated.
    >
    > greetings
    > Hans
    > --



    This archive was generated by hypermail 2.0.0 : Wed Aug 16 2006 - 10:16:26 EDT