Hi Martin,

Martin Heyer wrote:
Hello Ojb-Users.

I have a Cocoon + OJB installation running. For performance reasons there is a dynamic Proxy configured with class B. For example let's
have two classes A and B:

Class A: (has no proxy) - uid - link  -> points to uid of class B - B
(foreign key, holds the instance of B associated with link)

Class B: (has a proxy) - uid - data

Everything works fine without the proxy. But when proxy is turned on
and A points to an ID that has no B in the DB, it throws a NPE:

... Caused by: org.apache.ojb.broker.PersistenceBrokerException:
Error invoking method getIndirectionHandler at org.apache.ojb.broker.core.proxy.AbstractIndirectionHandler.invoke(AbstractIndirectionHandler.java:363)
 at $Proxy29.getIndirectionHandler(Unknown Source) ... 61 more Caused
by: java.lang.NullPointerException at org.apache.ojb.broker.core.proxy.AbstractIndirectionHandler.invoke(AbstractIndirectionHandler.java:347)
 ... 62 more

Is there a way to catch this? I can load A so it has a proxy instance
of B associated with it. ATM there is no way for me to know if the
proxy will find a real object of B. When I access this reference, it
crashes..

This should be fixed in SVN:
http://www.mail-archive.com/ojb-dev%40db.apache.org/msg03485.html

The only "workaround" I know is to patch method
AbstractIndirectionHandler.invoke(Object proxy, Method method, Object[] args)

replace:
return method.invoke(subject, args);

with:
if("toString".equals(methodName) && subject == null)
{
    return null;
}
if(subject == null)
{
log.warn("Real object of this proxy object doesn't exist, all method will return 'null': " + getIdentity());
    return null;
}
else
{
    return method.invoke(subject, args);
}

OR use your own IndirectionHandler implementation class e.g.
public class IndirectionHandlerCGLIBPatchedImpl extends IndirectionHandlerCGLIBImpl
{
...
}
and override the invoke-method in same way described above and declare it in OJB.properties file (IndirectionHandlerClass=...). But in this case you have use the reflection-API to get access to a private member "_realSubject" in AbstractIndirectionHandler.

regards,
Armin


I really would appreciate help,

Martin



---------------------------------------------------------------------
 To unsubscribe, e-mail: [EMAIL PROTECTED] For
additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to