This one time, at band camp, Thomas Louis said:

TL>to replace an Object in my Database, I do the following:
TL>
TL>db.begin();
TL>Product old = (Product)db.load(Product.class, new Integer(99));
TL>db.remove(old);
TL>Product new = new Product();
TL>new.setId(99);
TL>//....
TL>db.create(new);
TL>db.commit();
TL>
TL>But I'm getting
TL>org.exolab.castor.jdo.DuplicateIdentityException: Duplicate identity
TL>found for object of type Product with identity 99: an object with the
TL>same identity already exists in persistent storage
TL>
TL>Is this a bug? I deleted the object with id 99 before, but did not
TL>commit it. I don't want to commit, because if creation fails, the old
TL>Object would be lost. I also can't modify the old one, because I had to
TL>modify each of it's fields. It's much easyer to replace it completly.

Thomas,

You've answered your own question here. The remove() was not committed
yet so the cache see a duplicate id. Removal and creation of the
same object must take place in separate transactions. I understand
what you are saying when speaking about the loss of the old object.
Maybe in some try/catch blocks you can alleviate that loss by
recreating the old object if the creation of the new object fails.

Bruce
--

perl -e 'print unpack("u30","<0G)U8V4\@4VYY9&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");'

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

Reply via email to