| Summary: | testGetReferenceUsedInUpdate fails if run with eclipselink.weaving.changetracking=false | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | z_Archived | Reporter: | Andrei Ilitchev <andrei.ilitchev> | ||||||||
| Component: | Eclipselink | Assignee: | Nobody - feel free to take it <nobody> | ||||||||
| Status: | RESOLVED FIXED | QA Contact: | |||||||||
| Severity: | normal | ||||||||||
| Priority: | P3 | CC: | andrei.ilitchev, eclipselink.orm-inbox, guy.pelletier, peter.krogh, tom.ware | ||||||||
| Version: | unspecified | ||||||||||
| Target Milestone: | --- | ||||||||||
| Hardware: | PC | ||||||||||
| OS: | Windows XP | ||||||||||
| Whiteboard: | |||||||||||
| Attachments: |
|
||||||||||
|
Description
Andrei Ilitchev
bug scrub to 2.3.1 Created attachment 202095 [details]
Suggested patch
The test creates a reference then uses it as a target of OneToOne with a new object. Commit triggers the reference being read in - only if DeferredChangeTracking is used.
I am convinced that the behaviour of reference should be consistent no matter which change policy is used.
More importantly, if the object corresponding to the reference is not in the db - then exception should be thrown.
The question is whether the reference being referenced by another object should be triggered - even if there is no attempt to access its state (which is anything but pk).
The comment to EntityManager.getReference method leaves the door open for both behaviours:
/**
* Get an instance, whose state may be lazily fetched.
* If the requested instance does not exist in the database,
* the <code>EntityNotFoundException</code> is thrown when the instance
* state is first accessed. (The persistence provider runtime is
* permitted to throw the <code>EntityNotFoundException</code> when
* <code>getReference</code> is called.)...
The suggested patch assumes that Eclipselink will NOT trigger the reference unless its state is directly accessed.
Alternatively Eclipselink should have risen EntityNotFoundException right away if the object does not exist in the db - but currently its not the case.
The fix is simple - when DeferredChangeTrackingPolicy creates the change set don't set initial version value if the object has a FetchGroup that consists only of the PK (that used to trigger the reference).
EntitymanagerJUnitTestSuite.EntityNotFoundException should not have any special cases depending on which change tracking policy is used.
Created attachment 202450 [details]
Corrected patch
Corrected patch check for fetchGroup==null to avoid NPE on attempt to use FetchGroupManager when it is null.
Assigning to Andrei as he has a patch (and I have not been looking at this bug) Created attachment 203922 [details] Final patch Includes Andrei's patch and removal of test case change from bug 337365 for the testGetReferenceUsedInUpdate test. Changes submitted to 2.3.1 and trunk. Verified by: Gordon Yorke Tests: testGetReferenceUsedInUpdate test now passes with Andrei's fix and the reversal of the test change made in bug 337365 The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |