Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 314949

Summary: EclipseLink support multiple join columns without the reference column name specified
Product: [WebTools] Dali JPA Tools Reporter: Karen Butzke <karenfbutzke>
Component: JPAAssignee: Neil Hauge <neil.hauge>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P2 CC: brian.vosburgh, menno, neil.hauge
Version: 2.3   
Target Milestone: Future   
Hardware: PC   
OS: Windows XP   
Whiteboard: EclipseLink
Attachments:
Description Flags
project with an entity and and Embeddable none

Description Karen Butzke CLA 2010-05-28 15:37:06 EDT
Created attachment 170422 [details]
project with an entity and and Embeddable

Given this element collection, Dali has a validation error: 'Referenced column name must be specified when there are multiple join columns'. While this is true in the generic platform, EclipseLink supports this case and defaults the name to the id column. Easy workaround in Dali is just to specify the referencedColumnName

@Entity
public class Bar {
@Id
private int id;

private int discriminator;

@ElementCollection    
@CollectionTable(name="Foo" ,  
     joinColumns={
         @JoinColumn(name="id"), 
         @JoinColumn(name="owningEntity",referencedColumnName="discriminator")
     }
)
private Map<String, String> foo;
}

Second case, EclipseLink defaults the joinColumns to id->id and id2->id2:

@Entity
@IdClass(BarIdClass.class
public class Bar {
@Id
private int id;
@Id
private int id2;

@ElementCollection    
@CollectionTable(name="Foo")
private Map<String, String> foo;
}
Comment 1 Karen Butzke CLA 2010-09-17 15:13:46 EDT
I have created another bug (bug 325645) for the second example.
Comment 2 Nan Li CLA 2011-03-17 13:41:34 EDT
For the first case, this problem does not only happen with a collection table involved. It also happens with other relationship mappings using the joining strategy of join table or join columns. 

The fix could be remove the validation message on eclipselink platform for these cases by overriding the current validation of the generic platform, e.g. we can override buildJoinTableStrategy method of GenericJavaOneToManyRelationship in the class EclipseLinkJavaOneToManyRelationship. Currently, only OneToMany mapping has the eclipselink specific relationship implemetation. We would need to add the same thing for other relationship mappings if this is the right way to fix the probem.
Comment 3 Nan Li CLA 2011-03-17 14:25:23 EDT
For the second case, it's a problem related to the use of composite primary key. Basic on the EclipseLink behavior, there are different considerations:

1. The validation error message,'Referenced column name must be specified when there are multiple join columns', is still valid when only part of a join column pair of CollectionTable joinColumns or JoinTable joinColumns is specified.

2. A new validaiton should be given when only one join column pair is specified for CollectionTable joinColumns or JoinTable joinColumns.

3. Both validaitons should not apply when using the joining strategy of JoinColums.
Comment 4 Neil Hauge CLA 2011-03-18 16:37:56 EDT
(In reply to comment #2)
> For the first case, this problem does not only happen with a collection table
> involved. It also happens with other relationship mappings using the joining
> strategy of join table or join columns. 
> 
> The fix could be remove the validation message on eclipselink platform for
> these cases by overriding the current validation of the generic platform, e.g.
> we can override buildJoinTableStrategy method of
> GenericJavaOneToManyRelationship in the class
> EclipseLinkJavaOneToManyRelationship. Currently, only OneToMany mapping has the
> eclipselink specific relationship implemetation. We would need to add the same
> thing for other relationship mappings if this is the right way to fix the
> probem.


In addition, we also need to build the correct default value for the referenced column name, which is now defaulting to null in EclipseLink.  For the given example, the referenceColumnName default should be 'id' since it isn't specified.
Comment 5 Nan Li CLA 2011-03-21 14:47:21 EDT
The problems discussed should also apply to the Dali validation error "Name must be specified when there are multiple join columns" which applies to the missing name value of a join column.
Comment 6 Nan Li CLA 2011-03-22 12:11:07 EDT
Validation messages regarding unspecified join column/referenced column name should not apply for joinColumns of AssociationOverride.
Comment 7 Neil Hauge CLA 2011-07-01 16:26:51 EDT
Moving JPA specific bugs to new JPA component in bugzilla.
Comment 8 Karen Butzke CLA 2012-03-22 17:28:51 EDT
this is going to be too big for 3.2 and will probably involve API changes. i'm going to call this an enhancement though it involves invalid validation. It's a "feature" in EclipseLink and not supported by the JPA spec.
Comment 9 Neil Hauge CLA 2013-04-30 12:36:03 EDT
Deferred to 3.4.
Comment 10 Menno Jansz CLA 2014-01-10 05:37:14 EST
It's not just an EclipseLink feature. Hibernate also defaults the referenceColumnName in the same way.