[OJB-developers] bug when deleting with proxys
Brought to you by:
thma
From: Georg S. <ge...@me...> - 2002-03-07 15:47:57
|
Hi, I just encountered the following situation: I want to delete an object which I retrieved via an OQL-query The object itself is loaded dynamically. If I then try to execute the following db.deletePersistent(obj); I get the following error: org.odmg.ClassNotPersistenceCapableException: $Proxy2 not found in OJB Repository at ojb.odmg.ObjectEnvelope.manage(ObjectEnvelope.java:91) at ojb.odmg.ObjectEnvelope.<init>(ObjectEnvelope.java:73) at ojb.odmg.ObjectEnvelopeTable.get(ObjectEnvelopeTable.java:156) at ojb.odmg.TransactionImpl.markDelete(TransactionImpl.java:423) at ojb.odmg.DatabaseImpl.deletePersistent(DatabaseImpl.java:253) at imp.test.PersistenceTest.testPersistSimpleSequence(PersistenceTest.java:329) at imp.test.PersistenceTest.main(PersistenceTest.java:112) if I add a single line before the deletePersistent where I access some field in the object (which means that the actual object is materialized from the database) the deletion executes without an error. I looked at the ObjectEnvelopeTable class and obviously in the case that the object has not been materialized prior to deletion a new ObjectEnvelope is instantiated with the $Proxy2 class instead of the actual class. Since I haven't dug too much into ojb yet, I don't know how this should be done. Another thing, I wanted to mention is the fact that when one uses dynamic proxies, the class has to directly implement an interface. In my case for example some classes extend a baseclass which in turn implements an interface. e.g. BaseSequence implements Sequence SimpleSequence extends BaseSequence Unfortunately this leads to a ClassCastException in the following line after an OQL-Query: seq = (Sequence) seqs.get(0); The problem is that in RepositoryXMLHandler in private Class getDynamicProxyClass(ClassDescriptor cld) { ... Class[] interfaces = clazz.getInterfaces(); will only return the interfaces directly implemented by clazz and not the ones it 'inherits'. I suppose that one would have to walk through the tree of superclasses (and possibly also the interfaces itself, if they extend each other) to get a correct array of implemented interfaces. By the way, it is a pleasure to read through your clear code. regards Georg |