This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 241414 - JPA 2.0 Add support for a Uni-directional OneToMany mapping without Join Table
Summary: JPA 2.0 Add support for a Uni-directional OneToMany mapping without Join Table
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Andrei Ilitchev CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 241413 248291
  Show dependency tree
 
Reported: 2008-07-18 12:03 EDT by Gordon Yorke CLA
Modified: 2022-06-09 10:08 EDT (History)
3 users (show)

See Also:


Attachments
First patch (155.52 KB, patch)
2008-08-08 16:35 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Second patch (262.01 KB, patch)
2008-08-22 08:17 EDT, Andrei Ilitchev CLA
no flags Details | Diff
The second patch, revised (several test xml files corrected) (263.66 KB, patch)
2008-08-22 16:23 EDT, Andrei Ilitchev CLA
no flags Details | Diff
This patch should be applied on top of the previous one. (9.29 KB, patch)
2008-08-25 13:01 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Another small test patch to be applied on top of the prev. ones. (1.84 KB, patch)
2008-08-26 10:47 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Yet another small test patch to be applied on top of the prev. ones. (2.76 KB, text/plain)
2008-08-26 15:48 EDT, Andrei Ilitchev CLA
no flags Details
The last small test patch to be applied on top of the prev. ones. (6.79 KB, text/plain)
2008-08-27 15:26 EDT, Andrei Ilitchev CLA
no flags Details
The last small test patch to be applied on top of the prev. ones. (6.79 KB, patch)
2008-08-27 15:29 EDT, Andrei Ilitchev CLA
no flags Details | Diff
This patch adds batch reading support. (23.87 KB, patch)
2008-08-29 16:12 EDT, Andrei Ilitchev CLA
no flags Details | Diff
This patch enhances peformance (17.46 KB, patch)
2008-09-09 15:16 EDT, Andrei Ilitchev CLA
no flags Details | Diff
The patch adds target optimistic locking support (46.47 KB, patch)
2008-09-23 10:26 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Target optimistic locking support patch - updated as per James's comments. (48.21 KB, patch)
2008-09-23 15:44 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Target optimistic locking support patch - updated as per James's comments - take 2. (48.29 KB, patch)
2008-09-23 15:54 EDT, Andrei Ilitchev CLA
no flags Details | Diff
The patch fixes the test bug introduced by the previous patch. (653 bytes, patch)
2008-09-24 10:20 EDT, Andrei Ilitchev CLA
no flags Details | Diff
The patch adds UnidirectionalOneToMany mapping support to DDL generation (8.60 KB, patch)
2008-12-02 13:12 EST, Andrei Ilitchev CLA
no flags Details | Diff
The improvwed version of DDL generation patch. (14.66 KB, patch)
2008-12-02 13:43 EST, Andrei Ilitchev CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gordon Yorke CLA 2008-07-18 12:03:44 EDT
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.
Comment 1 Andrei Ilitchev CLA 2008-08-08 16:35:41 EDT
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.
Comment 2 Andrei Ilitchev CLA 2008-08-08 16:47:36 EDT
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.
Comment 4 Andrei Ilitchev CLA 2008-08-13 10:53:06 EDT
Feedback from James: target versioning should not be done (fk is not part of the object).
Next step - working on joining.
Comment 5 Andrei Ilitchev CLA 2008-08-22 08:17:29 EDT
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).
Comment 6 Andrei Ilitchev CLA 2008-08-22 16:23:42 EDT
Created attachment 110716 [details]
The second patch, revised (several test xml files corrected)

Correction for the second patch as per Guy's review.
Comment 7 Andrei Ilitchev CLA 2008-08-24 12:02:00 EDT
Checked in.
Comment 8 Andrei Ilitchev CLA 2008-08-25 13:01:12 EDT
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.
Comment 9 Andrei Ilitchev CLA 2008-08-26 10:47:31 EDT
Created attachment 110944 [details]
Another small test patch to be applied on top of the prev. ones.
Comment 10 Andrei Ilitchev CLA 2008-08-26 15:48:27 EDT
Created attachment 110993 [details]
Yet another small test patch to be applied on top of the prev. ones.
Comment 11 Andrei Ilitchev CLA 2008-08-27 15:26:00 EDT
Created attachment 111111 [details]
The last small test patch to be applied on top of the prev. ones.
Comment 12 Andrei Ilitchev CLA 2008-08-27 15:29:28 EDT
Created attachment 111112 [details]
The last small test patch to be applied on top of the prev. ones.
Comment 13 Andrei Ilitchev CLA 2008-08-29 16:12:10 EDT
Created attachment 111331 [details]
This patch adds batch reading support.
Comment 14 Andrei Ilitchev CLA 2008-08-29 16:22:00 EDT
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).
Comment 15 Andrei Ilitchev CLA 2008-09-09 15:16:50 EDT
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).
Comment 16 Andrei Ilitchev CLA 2008-09-09 17:07:20 EDT
Checked in the latest patch.
Comment 17 Andrei Ilitchev CLA 2008-09-23 10:26:03 EDT
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.
Comment 18 Andrei Ilitchev CLA 2008-09-23 15:44:59 EDT
Created attachment 113289 [details]
Target optimistic locking support patch - updated as per James's comments.
Comment 19 Andrei Ilitchev CLA 2008-09-23 15:54:52 EDT
Created attachment 113290 [details]
Target optimistic locking support patch - updated as per James's comments - take 2.
Comment 20 Andrei Ilitchev CLA 2008-09-23 16:08:18 EDT
Checked the patch in.
Comment 21 Andrei Ilitchev CLA 2008-09-24 10:20:39 EDT
Created attachment 113368 [details]
The patch fixes the test bug introduced by the previous patch.
Comment 22 Andrei Ilitchev CLA 2008-09-24 10:28:35 EDT
Checked the patch in.
Comment 23 Peter Krogh CLA 2008-11-24 10:16:01 EST
This feature has been completed
Comment 24 Andrei Ilitchev CLA 2008-12-02 13:12:42 EST
Created attachment 119296 [details]
The patch adds UnidirectionalOneToMany mapping support to DDL generation
Comment 25 Andrei Ilitchev CLA 2008-12-02 13:43:44 EST
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.
Comment 26 Andrei Ilitchev CLA 2008-12-02 13:45:57 EST
Checked the patch in.
Test: JPA 2.0 Add support for a Uni-directional OneToMany mapping without Join Table.testDDLUnidirectionalOneToMany
Comment 27 Eclipse Webmaster CLA 2022-06-09 10:08:28 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink