[ 
https://issues.apache.org/jira/browse/OPENJPA-2246?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Vermeulen updated OPENJPA-2246:
-------------------------------

    Attachment: openjpalazyeagerfetchplan.zip

Added a complete test case (build with Maven) which shows this bug.
                
> when using fetchplans a different entitymanager may incorrectly eagerly fetch 
> a lazy association
> ------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2246
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2246
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa, performance
>    Affects Versions: 2.1.1, 2.2.0
>            Reporter: Vermeulen
>         Attachments: openjpalazyeagerfetchplan.zip
>
>
> Setting a FetchPlan on an entitymanager which loads a certain @OneToMany 
> field that is marked as lazy and cascade all, can result in a different 
> entityManager (created by the same factory) to eagerly fetch this field, even 
> if the field is not in the fetchplan of this different entityManager.
> I found two situations where this occurs (each step uses a different 
> entityManager with a transaction):
> 1.
>  * em.merge a new entity (and cascaded related entity) with fetchgroup added
>  * find entity with no fetchgroup added
>   -> the lazy-fetched field is incorrectly loaded
> 2. 
>  * em.persist a new entity (and cascaded related entity) with NO fetchgroup 
> added
>  * find entity with fetchgroup added
>  * find entity with NO fetchgroup added
>   -> the lazy-fetched field is incorrectly loaded
> The weird thing is that persist and merge behave inconsistently - isn't that 
> great, an inconsistency within an inconsistency? - because switching 
> persist/merge results in the following situations that work as expected:
> 1.
>  * em.persist a new entity (and cascaded related entity) with fetchgroup added
>  * find entity with no fetchgroup added
>   -> the lazy-fetched field is a null reference (expected)
> 2. 
>  * em.merge a new entity (and cascaded related entity) with NO fetchgroup 
> added
>  * find entity with fetchgroup added
>  * find entity with NO fetchgroup added
>   -> the lazy-fetched field is a null reference (expected)
> Checking the trace and generated SQL confirms that the field that should not 
> be fetched is in fact fetched.
> I think this is a bug because this is both inefficient and is inconsistent 
> because I wish my data access to behave predictably.
> Note that turning on <property name="openjpa.DetachState" 
> value="fetch-groups" /> in persistence.xml solves the issues but internally 
> OpenJPA still performs the eager fetch.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to