I've ran into the following issue in Castor 0.9.3.9.  Note that this is NOT
a bug report.  I think I understand what is happening and why, so now I'm
looking for advice on how to deal with the problem.

Consider the following object structure:

   master <--> dependent1 --> leaf1

The master node actually has a one-to-many collection of dependents.

Let's add a new dependent to the master.  In doing so we need to get copies
of both master and a leaf.  My application has an abstract fa�ade layer on
top of Castor that loads and stores and updates objects, and it hides all
the transaction details so that no transactions extend beyond a single call
into the fa�ade.  So adding the new dependent looks like this:

    master = fa�ade.loadMaster(masterId);      // Transaction 1

    leaf = fa�ade.loadLeaf(leafId);            // Transaction 2

    dependent2 = new Dependent(master, leaf);

    master.addDependent(dependent2);

    fa�ade.updateMaster(master);               // Transaction 3


Now suppose that an existing dependent happens to use the same leaf, so that
my master looks like this just before the update:

   master <--> dependent1 --> leaf1
          <--> dependent2 --> leaf1

At this point its important to realize that the two copies of leaf1 above
are TWO SEPARATE INSTANCES since they were retrieved from castor in two
separate transactions.

When I attempt to update the master, Castor fails with a
DuplicateIdentityException as it attempts to update the second copy of
leaf1.

I understand one scenario where this may be desirable.  Suppose I made
different changes to both leaf instances, which changes would be used?  But
in this scenario I'm not changing either one, so there's no real problem.

How does one resolve this issue?  I've already got loads of graph-traversal
code in order to handle reloading objects for short-transaction stores, but
I've been hoping that it wouldn't be necessary when using long transactions.
Indeed this is the only stumbling block I can see to making Castor
transparent to the application.

(Sudden idea: Does the update work if the leaves are loaded read-only?)


Todd V. Jonker
Inpath Solutions, LLC
www.inpathsol.com

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

Reply via email to