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

Bug 364197

Summary: [Entity Gen] First time adding many-to-many association fails
Product: [WebTools] Dali JPA Tools Reporter: Nan Li <nan.n.li>
Component: JPAAssignee: Nan Li <nan.n.li>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: neil.hauge
Version: unspecified   
Target Milestone: 3.3 M2   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
stack trace
none
proposed patch neil.hauge: iplog+

Description Nan Li CLA 2011-11-18 15:44:10 EST
Build Identifier: I-3.4.0-20111117042436

1. Bring up the entity gen wizard, select a couple of tables and go to the Table Associations page
2. Click New Association button to bring up the Create New Association page
3. Select 'Many to many association' radio button, configure the association
tables properly, and click Finish

You will see the configured many to many association is not shown up on the wizard page. Adding it again will make it shown up; however, the remove button will be remaining enabled if removing the added association at this point, which leads to NPE exception if trying to click the remove button again.


Reproducible: Always
Comment 1 Nan Li CLA 2011-11-18 15:56:07 EST
Created attachment 207248 [details]
stack trace

stack trace for the NPE thrown when trying to click the remove association button after the association is already removed.
Comment 2 Nan Li CLA 2012-05-01 14:48:22 EDT
Created attachment 214887 [details]
proposed patch
Comment 3 Neil Hauge CLA 2012-07-05 18:02:54 EDT
Can you describe the changes made in the patch to fix the problem?  Specifically, what was causing the issue, and how it was addressed in the code.
Comment 4 Nan Li CLA 2012-07-06 11:34:30 EDT
A piece of the code of ORMGenCustomizer.getAssociations(boolean validOnly) is

if (mValidAssociations == null) {
  /*filter out the invalid associations*/ 
  mValidAssociations = new ArrayList<Association>(mAssociations.size());
  for (int i = 0, n = mAssociations.size(); i < n; ++i) {
	 Association association = mAssociations.get(i);
	 if (association.isValid()) {    <---
		mValidAssociations.add(association);
	 }
  }
}

At the line where the arrow points, it tries to verify if the association is valid which is done against the list of tables selected in the first page of the entity gen wizard. If choosing any one of tables in the database other than the selected tables for entities, the isValid() would return false so the association would not be added to the association list; therefore, the association will not show up after TableAssociationsWizardPage.updateAssociationsListPanel() is invoked. 

The changes I made in the patch, specifically in the class Association, are checking if a association is valid against the list of tables in the database instead of the list of selected table for entities. The rest of the changes in the patch is more code practice thing.
Comment 5 Neil Hauge CLA 2012-07-06 12:43:46 EDT
Thanks.  Patch committed to head.
Comment 6 Neil Hauge CLA 2012-10-16 14:24:40 EDT
This change was subsequently removed as this case involved tables not selected in the table selection screen.  All generation is based off of tables selected in the table selection screen and no others.