cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "kurt (JIRA)" <j...@apache.org>
Subject [jira] Created: (CAY-1423) auto-created newObject when setToOneTarget is used on an unbound entity-object
Date Thu, 15 Apr 2010 04:27:49 GMT
auto-created newObject when setToOneTarget is used on an unbound entity-object
------------------------------------------------------------------------------

                 Key: CAY-1423
                 URL: https://issues.apache.org/jira/browse/CAY-1423
             Project: Cayenne
          Issue Type: Question
         Environment: linux, Cayenne 3.0RC3, derby
            Reporter: kurt


setting a reference-attribute (via setToOneTarget) on an unbound object (i.e. not registered
in objectcontext) creates a newObject.

my code doing this looks like this:

    if (toOneAttributeNames().contains(attributeName))
      t.setToOneTarget(attributeName, (DataObject) value, false);
    else
      t.writeProperty(attributeName, value);

setting the primarykey-column (id) does not auto-register the entity in objectcontext (that
is ok for me)

querying the modifiedObjects and newObjects on objectcontext brings empty resultlist.

but setting an attribute, which is an relation (adresse) so that the method setToOneTarget
is used
registers the unbound entity in objectcontext (as newObject, but in the database this id already
exists):

modifiedObjects:
newObjects:
  {<ObjectId:Lieferant, TEMP:000000A4AEC70101>; new; [id=>1; toAdresse=>{<ObjectId:Adresse,
ID=1>}]}

having setReverse = true even creates a modified target-attribute (Adresse, which was _not_
modified before)

    if (toOneAttributeNames().contains(attributeName))
      t.setToOneTarget(attributeName, (DataObject) value, true);
    else
      t.writeProperty(attributeName, value);

modifiedObjects:
  {<ObjectId:Adresse, ID=1>; modified; [whg=>EUR; www=>; land=>; id=>1;
lieferants=>(..); ]}
newObjects:
  {<ObjectId:Lieferant, TEMP:000000A4AEC70101>; new; [id=>1; toAdresse=>{<ObjectId:Adresse,
ID=1>}]}


the problem with that is, that on the next commit, cayenne creates an INSERT on that newObject
which in turn
results in a duplicate key exception.

my questions now are:

  shouldn't the "setter-methods" of the entities (setToOneTarget and writeProperty)
  result in kind of similar behaviour in respect of auto-registering new/modified objects
?

  should that different behaviour considered to be a bug ?

(ofcourse i can code around that problem, but it would make development of abstractions easier)



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message