You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Jean-Baptiste BRIAUD -- Novlog <j-...@novlog.com> on 2009/07/30 12:02:27 UTC

How to get rid of proxy ?

Hi the list !

After long investigation, my previous problem come from a proxy.
I have a collection of B in A. Using fetch plan, I removed B and get  
back my A without B witch is good.

Somewhere, I have the following code :
This happen after the transaction is closed, I explicitly close the  
entityManager when this code happen.

         if (getB() != null) {
             result = new B[getB().size()]; // It fail here on .size
             int index = 0;
             for (B b : getB()) {
                 result[index] = b;
                 index++;
             }
         }

This code fails when I called getB().size().
Because of the proxy (that's what I guessed) getB() is not null but  
the data is not there because I removed it from the fetch plan.
getB() != null doesn't catch the case of "B not retreive due to fetch  
plan".
That could be fine is getB().size() returned 0 but it failed on null  
pointer exception !

The stack trace look like OpenJPA, because of proxy, try to get B from  
the database but I don't want that, I want null that's why I remove B  
from fetch plan, I don't want B.
If I want B, witch will happen in some other cases, I'll add B to the  
fetch plan but that owuld be in totally different transaction and  
business context.

Basically, the question could be how to get rid of proxy and get null  
values, even if they are in the DB but I removed it from the fetch  
plan so I "tell" to OPenJPA I know what I'm doing.

Is this possible ?

Re: How to get rid of proxy ?

Posted by Jean-Baptiste BRIAUD -- Novlog <j-...@novlog.com>.
up : so it is possible not to have proxy for not retreived values when  
using fetch plan ?

Thanks for your ideas !

On Jul 30, 2009, at 12:02 , Jean-Baptiste BRIAUD -- Novlog wrote:

> Hi the list !
>
> After long investigation, my previous problem come from a proxy.
> I have a collection of B in A. Using fetch plan, I removed B and get  
> back my A without B witch is good.
>
> Somewhere, I have the following code :
> This happen after the transaction is closed, I explicitly close the  
> entityManager when this code happen.
>
>        if (getB() != null) {
>            result = new B[getB().size()]; // It fail here on .size
>            int index = 0;
>            for (B b : getB()) {
>                result[index] = b;
>                index++;
>            }
>        }
>
> This code fails when I called getB().size().
> Because of the proxy (that's what I guessed) getB() is not null but  
> the data is not there because I removed it from the fetch plan.
> getB() != null doesn't catch the case of "B not retreive due to  
> fetch plan".
> That could be fine is getB().size() returned 0 but it failed on null  
> pointer exception !
>
> The stack trace look like OpenJPA, because of proxy, try to get B  
> from the database but I don't want that, I want null that's why I  
> remove B from fetch plan, I don't want B.
> If I want B, witch will happen in some other cases, I'll add B to  
> the fetch plan but that owuld be in totally different transaction  
> and business context.
>
> Basically, the question could be how to get rid of proxy and get  
> null values, even if they are in the DB but I removed it from the  
> fetch plan so I "tell" to OPenJPA I know what I'm doing.
>
> Is this possible ?
>