This discussion is archived
3 Replies Latest reply: Nov 25, 2011 6:35 AM by 888359 RSS

Null reference with Proxy Indirection

888359 Newbie
Currently Being Moderated
Hi,

I'm using the Proxy indirection in a 1-1 mapping. I got the exception [TOPLINK-7103] because I'm calling a getter on the mapped field which is null.
But when the object isn't null (it's an instance of IndirectProxy), so I cannot compare it to null .

I got the exception with the following code:
Nationality nationality = address.getNationality();
if(nationality != null){
          nationality.getCode(); //nationaly isn't null but the proxy hold a null reference               
}

Any idea?

The exception message told me to check the null ref before calling a method, but I don't know how to check that.
  • 1. Re: Null reference with Proxy Indirection
    JamesSutherland Pro
    Currently Being Moderated
    You could use normal indirection, or use JPA with weaving. Proxy indirection it not normally used.

    You could catch the error, or check for the proxy cast to ProxyIndirectionHandler and get the valueHolder's value from it to check if it is null.

    Normally you would not get a proxy on null in a normal 1-1 mapping as the foreign key will be null, so EclipseLink will not build the proxy. Perhaps ensure your mapping uses a foreign key.

    ---
    James : http://www.eclipse.org/eclipselink/
  • 2. Re: Null reference with Proxy Indirection
    888359 Newbie
    Currently Being Moderated
    You're right. Even though this is not th normal use, it fits our situation.

    For now I've found the following work around :
    I call the equals method on null, which has been overriden in the ProxyHandler. But it triggers the loading of the reference.

    Edited by: krampstudio on Nov 25, 2011 5:41 AM

    Edited by: krampstudio on Nov 25, 2011 5:42 AM
  • 3. Re: Null reference with Proxy Indirection
    888359 Newbie
    Currently Being Moderated
    answered in previous post. I finally use the equals method that compare the needed object instead of the Proxy but it triggers the data loading. So I use it when I really need it.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points