Community
Participate
Working Groups
see: http://wiki.eclipse.org/EclipseLink/Development/JPA2.0/uni-directional_onetomany_mapping In JPA 2.0 support is required for having a uni-directional OneToMany mapping that will not use a Join Table for the relationship.
Created attachment 109564 [details] First patch This patch is a first stub at UnidirectionalOneToManyMapping. It's core-only (no jpa support yet) and not complete, but functional in simple cases and contains tests (insert source object, delete source object, add an remove target objects to/from source object; read tests). "Simple cases" means that this patch doesn't support yet some advanced features like: 1. optimistic locking of target objects (if the target object added or removed to/from the source its version should change - currently doesn't work); 2. no support for history policy yet; 3. batch writing/reading was not tested; 4. ?? What's next? The first priority to add OptimisticLocking support. Gordon's suggestion: If indirection hasn't been triggered - don't trigger it, but rather issue sql that updates all target objects in the db and sets the correct version into them. Such update will never fail with OptimisticLock exception (which is correct - we haven't cached the target objects), however may cause OptimisticLock exception in another thread that cached the target objects and tryes to update them after us (which is the way it should be). In indirection has been instantiated - loop through all the target objects individually, call uow.forceUpdateToVersionField(target, true) for each target (that would take care of merging the right version into the object in cache), then issue sql for each target that would update both foreign key and version.
Correction: uow.forceUpdateToVersionField(target, true) also writes takes care of writing the correct version into the db; therefore the sql need only update the target's foreign key.
The design doc: http://wiki.eclipse.org/EclipseLink/Development/JPA2.0/uni-directional_onetomany_mapping
Feedback from James: target versioning should not be done (fk is not part of the object). Next step - working on joining.
Created attachment 110668 [details] Second patch This patch adds JPA support for UnidirectionalOneToManyMappings and cleans up existing support in core. This is NOT final patch - still to be addressed are: batch reading; target locking; some kind of mechanism to avoid conflicts when removing target (or assigning the new source to the target that might conflict with the old one).
Created attachment 110716 [details] The second patch, revised (several test xml files corrected) Correction for the second patch as per Guy's review.
Checked in.
Created attachment 110820 [details] This patch should be applied on top of the previous one. This patch fixes jpa xml test problems introduced by the previous patch.
Created attachment 110944 [details] Another small test patch to be applied on top of the prev. ones.
Created attachment 110993 [details] Yet another small test patch to be applied on top of the prev. ones.
Created attachment 111111 [details] The last small test patch to be applied on top of the prev. ones.
Created attachment 111112 [details] The last small test patch to be applied on top of the prev. ones.
Created attachment 111331 [details] This patch adds batch reading support.
Checked the latest patch in, code review by James is pending. The main part of the feature is completed. The items left: 1. Incrementing target's version on adding / removing it from a source. 2. Relation maintenence (on deletion of the target or target changing source); 3. History support. Should these items be postponed for the future? Also pending is a clean-up of the code and comments (along with the original code review by James).
Created attachment 112120 [details] This patch enhances peformance Use List's get method for looping instead of Enumerations and Iterators; cache the size before looping, direct access to the variables; use the class cached in the DatabaseField (instead of calculating it everytime pk is extracted).
Checked in the latest patch.
Created attachment 113255 [details] The patch adds target optimistic locking support The target version is incremented in case the target is added to (or removed from) the source; also in case the source is deleted. That means that the target version is always incremented if foreign key is changed. Note that on source deletion the target indirection is triggered, and its possible to get OptimisticLocking exception because the target has been changed by another thread.
Created attachment 113289 [details] Target optimistic locking support patch - updated as per James's comments.
Created attachment 113290 [details] Target optimistic locking support patch - updated as per James's comments - take 2.
Checked the patch in.
Created attachment 113368 [details] The patch fixes the test bug introduced by the previous patch.
This feature has been completed
Created attachment 119296 [details] The patch adds UnidirectionalOneToMany mapping support to DDL generation
Created attachment 119298 [details] The improvwed version of DDL generation patch. As per Guy's review the new patch removes the no longer uysed Validation exception and the corresponding resource. Also added the new test entity that was forgotten in the original patch.
Checked the patch in. Test: JPA 2.0 Add support for a Uni-directional OneToMany mapping without Join Table.testDDLUnidirectionalOneToMany
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink