This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 282553 - JPA 2.0 JoinTable support for OneToOne and ManyToOne
Summary: JPA 2.0 JoinTable support for OneToOne and ManyToOne
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 265319 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-07-06 13:32 EDT by Andrei Ilitchev CLA
Modified: 2022-06-09 10:23 EDT (History)
3 users (show)

See Also:


Attachments
Suggested patch. (360.40 KB, patch)
2009-07-06 14:02 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Corrected patch (432.38 KB, patch)
2009-07-13 16:17 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Final patch. (441.36 KB, patch)
2009-07-16 11:27 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Correction patch. (27.04 KB, patch)
2009-07-17 15:48 EDT, Andrei Ilitchev CLA
no flags Details | Diff
JPA metadata processing implementation (103.21 KB, patch)
2009-09-29 12:57 EDT, Guy Pelletier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrei Ilitchev CLA 2009-07-06 13:32:41 EDT
As per spec. (11.1.23 JoinTable Annotation):
A join table is typically used in the mapping of
many-to-many and unidirectional one-to-many associations. 
It may also be used to map bidirectional
many-to-one/one-to-many associations and one-to-one associations.
Comment 1 Andrei Ilitchev CLA 2009-07-06 14:02:22 EDT
Created attachment 140894 [details]
Suggested patch.

Lots of code copied from ManyToManyMapping.
A new OneToOneJoinTableEmployeeBasicTestModel is created.
Comment 2 Andrei Ilitchev CLA 2009-07-13 16:17:58 EDT
Created attachment 141454 [details]
Corrected patch

The corrected patch declares a new class RelationTableMethod that holds all the relation table - related functionality (which is now shared between ManyToMany and OneToOne).

Now the user can setup relation table in the same way on OneToOne and ManyToMany:
addressMapping.setRelationTableMechanism(new RelationTableMechanism());
addressMapping.getRelationTableMechanism().setRelationTableName("OTOJT_EMP_ADDRESS");
addressMapping.getRelationTableMechanism().addSourceRelationKeyFieldName("OTOJT_EMP_ADDRESS.EMP_ID", "OTOJT_EMPLOYEE.EMP_ID");
addressMapping.getRelationTableMechanism().addTargetRelationKeyFieldName("OTOJT_EMP_ADDRESS.ADDR_ID", "OTOJT_ADDRESS.ADDRESS_ID");

This is the only possible way to set up relation table on OneToOneMapping,
but on ManyToManyMapping the "old" way could be used, too:
projectsMapping.setRelationTableName("OTOJT_PROJ_EMP");
projectsMapping.addSourceRelationKeyFieldName("OTOJT_PROJ_EMP.EMP_ID", "OTOJT_EMPLOYEE.EMP_ID");
projectsMapping.addTargetRelationKeyFieldName("OTOJT_PROJ_EMP.PROJ_ID", "OTOJT_PROJECT.PROJ_ID");

Added some expression tests.
Comment 3 Andrei Ilitchev CLA 2009-07-14 16:55:36 EDT
Link to the doc:
http://wiki.eclipse.org/EclipseLink/Development/JPA2.0/one-to-one_via_jointable
Comment 4 Andrei Ilitchev CLA 2009-07-16 11:27:44 EDT
Created attachment 141794 [details]
Final patch.

Moved relation row building ifrom mappings nto RelationMechanism class.
The patch checked into trunk.
Comment 5 Andrei Ilitchev CLA 2009-07-16 11:28:20 EDT
Fixed.
Comment 6 Andrei Ilitchev CLA 2009-07-17 15:48:35 EDT
Created attachment 141919 [details]
Correction patch.

Some 13 tests that I added failed on MySql. This patch corrects the problems:
1. EmployeePopulator didn't round times causing comparison to fail - it's a test problem;
2. BatchRead code that extracts source keys from relation table didn't convert them using source field type - that caused read objects not found in the map of batched objects (CacheKey that has is not equal to the one with  BigDecimal);
3. SQLSelectStatement.appendFromClauseForOuterJoin failed to use relation table in OneToOne case - now the same code is shared between ManyToMany and OneToOne with relation table.
Comment 7 Andrei Ilitchev CLA 2009-07-17 16:04:47 EDT
Correction patch checked into trunk.
Comment 8 Guy Pelletier CLA 2009-08-10 10:32:52 EDT
Re-opening the bug as the metadata processing portion of this bug have not been completed and will be submitted against this bug.
Comment 9 Gordon Yorke CLA 2009-09-23 13:36:00 EDT
*** Bug 265319 has been marked as a duplicate of this bug. ***
Comment 10 Guy Pelletier CLA 2009-09-29 12:57:30 EDT
Created attachment 148341 [details]
JPA metadata processing implementation
Comment 11 Guy Pelletier CLA 2009-09-30 09:57:28 EDT
Changes have been submitted.

Reviewed by: Tom Ware

Tests: New test (testOne2OneRelationTables) added to both EntityMappingsRelationshipsJUnitTestCase and RelationshipModelJUnitTestSuite
Comment 12 Eclipse Webmaster CLA 2022-06-09 10:23:08 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink