[ 
https://issues.apache.org/jira/browse/IBATIS-596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12710370#action_12710370
 ] 

Stefan Gmeiner commented on IBATIS-596:
---------------------------------------

We found 2 more problems with lazy loading:

1. The Cglib-Proxy uses the parameter type instead of the result set type for 
creating a proxy object. This could be sometimes problematic if the client 
wants to casts from the parameter type to the result type. The attached file 
contains a test EnhancedLazyResultLoaderTest.testProxyType() for this problem 
and a patch to EnhancedLazyResultLoader.

2. If a proxy was created but not initialized and some times later the record 
for this proxy was deleted in the database all method calls to this proxy 
returns null. We think that this situation should be more explicit by throwing 
an exception in that case. See also the test 
WholePartTest.testDeletedLazyLoadedRelation() in the attached file.



> Null-References for sub selects with lazy loading
> -------------------------------------------------
>
>                 Key: IBATIS-596
>                 URL: https://issues.apache.org/jira/browse/IBATIS-596
>             Project: iBatis for Java
>          Issue Type: Improvement
>          Components: SQL Maps
>    Affects Versions: 2.3.4
>            Reporter: Stefan Gmeiner
>             Fix For: 2.3.5
>
>         Attachments: null-proxy.patch, test-null-proxy.patch
>
>
> We are using the iBatis enhanced (cglib) proxy for lazy loading our 
> sub-select bean references.
> Unfortunately if a reference is null iBatis creates a proxy with
> null content. This makes using lazy loading less transparent to clients as 
> they are required
> to execute further checks to see if the returned object is null.
> Hence we are suggesting a simple solution which is attached as a patch:
> A proxy for a lazy loaded object is now only created if the foreign key is 
> non-null.
> When using the curly braces syntax (parameter map) a postfix '?' is required 
> to activate
> the new lazy loading otherwise the existing strategy is used. This allows for 
> the possibility
> of subselects requiring a null value as foreign key.
> Example:
> <result property="jobs" column="job_pk" select="selectJob"/>
> This will return null if job_pk is null and a proxy for the job is job_pk is 
> not null.
> <result property="jobs" column="{transportIdentifier=job_pk}" 
> select="selectJob"/>
> This will always return a proxy object irrespective of the job_pk value.
> <result property="jobs" column="{transportIdentifier=job_pk?}" 
> select="selectJob"/>
> This will return null if job_pk is null and a proxy for the job is job_pk is 
> not null.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to