tags:

views:

89

answers:

1

Hi, I am having an issue while using Apache OJB with Spring 2 inside my web app.

I'm using OJB reference-descriptor with 2 foreign key properties. I have an object A (parent) and object B (referenced object). The thing is, for an object A, there may or may not be an object B.

In the case where there is no object B to go with Object A, the object B seems to be instantiated (through Spring?) anyways. However, I am unable to access object B's members.

Whenever I test if Object B == null, it always returns false even though there is no matching value in the database.

Since this Object is never null, I figured I can test the object's member like so:

if( objectb.getDocumentNumber == null) { return false; }

However, I get an exception in the jsp:

javax.servlet.jsp.el.ELException: An error occurred while getting property
"documentNumber" from an instance class
org.sample.pojo.Objectb$$EnhancerByCGLIB$$78022a2

and this exception in the debugger when it's creating the objectB:

com.sun.jdi.InvocationException occurred invoking method.

I am guessing that the reference-descriptor must be a 1:1+ relationship, instead of a 1:0+ relationship. I was wondering if I should set the property 'auto-retrieve' to false, and then use the PersistenceBroker.retrieveAllReferences(Object obj); method as directed. However, this method's return value is 'void', so I am guessing that Spring somehow creates, and sets the reference class for me. (Returning me back to the same issue I'm having.)

I will need a way to test whether the reference object exists first. If not, don't call this retrieveAllReferences method, but I don't see how.

Am I going about this all wrong? Does reference-descriptor not allow 1:0 relations? Any work around to my problem?

Your suggestions are greatly appreciated!

A: 

I figured it out. Just in case it will help anyone else, i set proxy = false.

This works for me, because by setting it to false, it won't create a temporary reference object, and I could test for null with that.

Thanks anyways.