Hi.

I have an object "Master" with a one-to-many relationship to a dependent
object
"Dependent" (depends="master" in the xml file). The relation is being marked
as
"lazy". Both objects use key generators.

I want to add ONE new instance of "Dependent" to the collection of "Master".
But
the following code will create TWO entries of "Dependent" in the database:

----+----+----+----+----
// get database, load master, add a new instance of Dependent
Database db = jdo.getDatabase();
db.begin();
Master master = db.load(...);
Dependent dep = new Dependant();
dep.setMaster(master);
master.getDependents().add(dep);
db.commit();

// Reuse the object "master"
db = jdo.getDatabase();
db.begin();
db.update(master);
db.commit();

// Now we have TWO new dependents
----+----+----+----+----

I guess that the problem is the following:

1. Right before the first commit, "master.getDependents()" returns an
instance
of RelationCollection with one entry in "_added". That's correct.

2. Right after the first commit, "master.getDependents()" returns the same
RelationCollection (okay), but "_added" still contains one entry! This may
be
the problem.

3. Right before the second commit, "master.getDependents()" - guess what -
still
has one entry in "_added". The same dependent object will be created again.

As far as I can see, the RelationCollection should be reset during the first
commit. "_added", "_deleted" and "_changecount" should be reset.


Martin

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to