Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 364093 - [Entity Gen] Many-to-many association cannot be generated correctly
Summary: [Entity Gen] Many-to-many association cannot be generated correctly
Status: NEW
Alias: None
Product: Dali JPA Tools
Classification: WebTools
Component: JPA (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: Future   Edit
Assignee: Nan Li CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-17 18:02 EST by Nan Li CLA
Modified: 2013-07-05 11:53 EDT (History)
1 user (show)

See Also:


Attachments
Proposed Patch (1.81 KB, patch)
2012-07-11 17:18 EDT, Nan Li CLA
no flags Details | Diff
additional patch (2.57 KB, patch)
2012-09-10 14:34 EDT, Nan Li CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nan Li CLA 2011-11-17 18:02:31 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 and configure the association tables properly
4. Complete the rest steps and click Finish

Check the generated entities and you'll see the join strategy for the customized ManyToMany association is JoinColumn instead of configured JoinTable and the properties set to the join table are lost.



Reproducible: Always
Comment 1 Nan Li CLA 2012-05-02 11:29:41 EDT
Dynamic entity gen wizard has the same issue. With customized many-to-many association the corresponding generated XML piece likes:

<many-to-many name="projects" target-entity="model.Project" attribute-type="java.util.List">
	<join-column name="PROJ_ID"/>
</many-to-many>

Thinking that's because both wizard uses the same code base.
Comment 2 Nan Li CLA 2012-06-18 16:29:45 EDT
JoinTable strategy is applied if join table set at step 3 is one of the tables chosen at step 1; otherwise, JoinColumn strategy is applied.
Comment 3 Nan Li CLA 2012-07-11 17:18:49 EDT
Created attachment 218602 [details]
Proposed Patch
Comment 4 Neil Hauge CLA 2012-07-13 16:46:35 EDT
(In reply to comment #2)
> JoinTable strategy is applied if join table set at step 3 is one of the tables
> chosen at step 1; otherwise, JoinColumn strategy is applied.

I think this is actually the expectation of how the wizard is supposed to work.  If you were to not select a join table that was used in a inferred association, the M-M association wouldn't be created either.

I guess the question is whether we should change this "as designed" behavior for the case where an association is being added and the desired join table hasn't already been selected by the user.  Since the table is not selected in the initial wizard page, generally speaking, this table would be seen as being out of context to the following operations.  Perhaps this decision should be revisited though.
Comment 5 Nan Li CLA 2012-07-13 17:06:05 EDT
I got what you mean and I overlooked one thing that no entity is generated for the table chosen as the join table. I thought entities would be generated for all the chosen tables. But M-M does not support JoinColumn strategy. Was it ever supported, e.g. with JPA 1.0? Anyway, I agree that we need to rethink how things should work along with a change I made previously to let use choose join table from the list of table in the database instead of the list of chosen tables.
Comment 6 Neil Hauge CLA 2012-07-13 17:16:27 EDT
Yeah...Many to Many shouldn't be defining a JoinColumn strategy.  The generator isn't handling this error case very well.
Comment 7 Neil Hauge CLA 2012-09-10 11:13:37 EDT
I think we should just defer this enhancement for now, given that the scope of the work to address it has gotten too large.  We have bigger issues to deal with, and we haven't had any external bugs reported in this area.  We can also roll back the fix for the other bug that you mentioned in comment 5.
Comment 8 Nan Li CLA 2012-09-10 14:34:52 EDT
Created attachment 220904 [details]
additional patch

This patch is for rolling back previous fix for handling join table. Users will still select join table from the list of selected tables instead of the list of available tables in the database.
Comment 9 Nan Li CLA 2012-09-10 15:45:04 EDT
This patch is based on the following commit:

2895790 removed now unnecessary validation methods Karen Butzke
Comment 10 Neil Hauge CLA 2012-09-10 17:13:05 EDT
Just to make this a little less confusing, we should probably attach the additional patch on the related bug 362203 instead of this one for better tracking.
Comment 11 Nan Li CLA 2012-09-11 09:53:40 EDT
I thought to put the additional patch to bug 362203, but the fix for bug 362203 is only partially related to the changes in the new patch and not all the changes of it were rolled back. I was thinking it would be easier to find all the related parties that need to be changed while fixing this bug so I attached the patch with this bug. I can also attach the new patch to bug 362203 and list the related bugs here if you prefer. If so, I assume that I am suppose to reopen bug 362203.
Comment 12 Neil Hauge CLA 2012-09-11 17:35:50 EDT
(In reply to comment #11)
OK...that sounds fine.  We can just make a comment in bug 362203 that mentions this.  I can commit the additional patch and we can leave this bug open for the future.
Comment 13 Nan Li CLA 2012-09-11 18:04:25 EDT
The following bugs should be taken into consideration when fixing this bug:

bug 362203
bug 364197

The decision made for this bug could affect the fix for the bugs above.
Comment 14 Nan Li CLA 2012-09-12 10:57:03 EDT
Comment on attachment 220904 [details]
additional patch

We don't need this additional patch to roll back changes since no changes need to be rolled back.
Comment 15 Nan Li CLA 2012-09-24 16:36:22 EDT
One more bug to consider when fixing this bug: bug 364201

Currently, entity gen wizard gives all the available tables in the database for join table, which means user can choose any table as the join table; however, it seems everything works properly only when the join table is one of the previous selected tables.