The problem seems to be that when the enclosing class is materialized, the reference class is not yet looked up in the database. So, we don't know if it is null or not. All we can do is make the enclosing class reference a proxy class that will perform the db lookup when the field is referenced. I don't see how the original reference to the proxy can be replaced with a null, as suggested in
http://www.mail-archive.com/[EMAIL PROTECTED]/msg00132.html
I think the problem lies with the org.apache.ojb.broker.accesslayer.IndirectionHandler class. After the real subject is materialized from the db, no check is performed as to whether the subject is null. Instead, the method is simply called on the subject -- even if it is null.
To me, the most transparent way of handling this problem would be to simply return null if the materialized subject is null.
Does that make sense? Thanks Andrew
Index: IndirectionHandler.java
===================================================================
RCS file: /home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/accesslayer/IndirectionHandler.java,v
retrieving revision 1.21
diff -u -r1.21 IndirectionHandler.java
--- IndirectionHandler.java 28 Oct 2003 21:21:19 -0000 1.21
+++ IndirectionHandler.java 18 Nov 2003 18:25:35 -0000
@@ -282,6 +282,13 @@
}
subject = getRealSubject();
+ + // if the proxied, underlying object is null, return null for
+ // any and all of its properties
+ if (subject == null) {
+ return null;
+ }
+ return method.invoke(subject, args);
// [olegnitz] I've changed the following strange lines
// to the above one. Why was this done in such complicated way?
[EMAIL PROTECTED] wrote:
2) How can I check whether a proxy reference is null? Is there a way to do this transparently?
You may use the ProxyHelper class to materialize the proxy. However, this defeats the purpose of proxies because it is not transparent.
I've read other messages in the archive about this issue, but I haven't really seen a solution to it. The solution proposed here didn't seem to do anything for me: http://www.mail-archive.com/[EMAIL PROTECTED]/msg00132.html
I do not understand that. I had the same problem and that tip helped me.
Can you assemble a junit test or small test case that reveals the problem?
Olli
--------------------------------------------------------------------- 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]
