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

Bug 357941

Summary: ArrayIndexOutOfBoundsException when switching from PrimaryKeyJoinColumn strategy to mappedBy
Product: [WebTools] Dali JPA Tools Reporter: Nan Li <nan.n.li>
Component: JPAAssignee: Karen Butzke <karenfbutzke>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jolene.moffitt, karenfbutzke
Version: unspecified   
Target Milestone: 3.1 M2   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
stack trace none

Description Nan Li CLA 2011-09-16 09:45:44 EDT
Build Identifier: I20110805-1200

For one to one mapping, if first setting the joining strategy to PrimaryKeyJoinColumn  and then changing it to mappedBy, an ArrayIndexOutOfBoundsException will be thrown like

java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
	at java.util.Vector.remove(Unknown Source)
	at org.eclipse.jpt.common.utility.internal.model.ChangeSupport.removeItemFromList(ChangeSupport.java:2056)

Full stack trace is attached. 

Reproducible: Always

Steps to Reproduce:
1. Define a one to one mapping
2. Go to JPA Details -> Joining Strategy and select Primary key join columns radio button
3. Select Mapped by radio button
Comment 1 Nan Li CLA 2011-09-16 09:47:03 EDT
Created attachment 203485 [details]
stack trace
Comment 2 Nan Li CLA 2011-09-16 10:59:19 EDT
some more comments:

Switching from PrimaryKeyJoinColumn  to JoinTable has the same problem. 

Switching from PrimaryKeyJoinColumn  to JoinColumn leads to no annotation written to the source.

After switching from PrimaryKeyJoinColumn  to JoinTable or JoinColumn, trying to change the attribute mapping type, e.g. from OneToOne to OneToMany will get org.eclipse.swt.SWTException: Failed to execute runnable (java.util.NoSuchElementException).

I am thinking they are all related so I put comments here. Let me know if I need to do something else. Thanks!
Comment 3 Karen Butzke CLA 2011-09-16 16:44:47 EDT
They all look related to me! One thing, when you switch to Join Columns it is correct that no JoinColumn annotation is added. That is the default strategy and at that point you have the 1 default join column.
(In reply to comment #2)
> Switching from PrimaryKeyJoinColumn  to JoinTable has the same problem. 
This one definitely looks like the same problem

> Switching from PrimaryKeyJoinColumn  to JoinColumn leads to no annotation
> written to the source.
I think this is correct because join column is the default strategy, at that point you have the 1 default join column.

> After switching from PrimaryKeyJoinColumn  to JoinTable or JoinColumn, trying
> to change the attribute mapping type, e.g. from OneToOne to OneToMany will get
> org.eclipse.swt.SWTException: Failed to execute runnable
> (java.util.NoSuchElementException).

This one appears to be unrelated, just having a 1-1 mapping with a JoinTable or JoinColumn on it and changing it to a 1-m mapping causes this problem. I'll enter another bug or see if it's potentially related to the container annotation issues found in bug 357691.
Comment 4 Karen Butzke CLA 2011-09-19 11:21:41 EDT
fixed for M2
Comment 5 Jolene Moffitt CLA 2011-09-27 12:56:20 EDT
Verified in Build I-3.4.0-20110922230524 

Verified you can change the joining strategy for a mapping without error.  See the link to view test steps for verification. http://wiki.eclipse.org/Dali_3.1_M2