You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Mario Curcija <Ma...@lex-com.net> on 2008/04/03 10:39:32 UTC
ImageException during object removal from M:N relationships in OJB 1.0.5rc1
with implicitLocking=false
Hi ojb-users,
similar problem was already discussed in following thread:
http://www.mail-archive.com/ojb-user@db.apache.org/msg14793.html.
As I see from:
ObjectEnvelope.removedXToN(CollectionDescriptor, Object, Identity)
An ImageException "Unexpected behaviour, unregistered object performed …"
is thrown because referenced object was not registered (and locked) and
ObjectEnvelope is null in that case (as a result of
implicitLocking=false).
Of course I’m aware of the fact that in this case the user should take
responsibility for locking and registering objects within
odmg-transaction.
I’m wondering if this method should really check if referenced object was
registered with transaction and implicitly register it in a similar way as
it is done in:
ObjectEnvelope.addedXToN(CollectionDescriptor, Object, Identity)
ObjectEnvelope mod = buffer.getByIdentity(oid);
// if the object isn't registered already, it can be 'new' or
already 'persistent'
if(mod == null)
{
mod = buffer.get(new RuntimeObject(refObjOrProxy, oid,
getTx()));
}
This problem can be reproduced if we drop new test method in
org.apache.ojb.odmg.ObjectImageTest. For example:
public void testImageExceptionOnRemovingReferenced()
{
String name = "testImageExceptionOnRemovingReferenced_" +
System.currentTimeMillis();
Date date = new Date();
byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
Book book = new Book(name, date, cover);
Review r1 = new Review(name);
TransactionExt tx = (TransactionExt) odmg.newTransaction();
tx.begin();
database.makePersistent(book);
database.makePersistent(r1);
tx.commit();
/* add without implicit locking - should pass */
tx = (TransactionExt) odmg.newTransaction();
tx.setImplicitLocking(false);
tx.begin();
tx.lock(book, Transaction.WRITE);
book.addReview(r1);
tx.commit();
/* remove without implicit locking - fails */
tx = (TransactionExt) odmg.newTransaction();
tx.setImplicitLocking(false);
tx.begin();
tx.lock(book, Transaction.WRITE);
book.removeReview(r1);
tx.commit();
}
Best regards,
Mario Curcija