This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 101478 - Entity Wizard generate incorrect ManyToMany relationship mapping
Summary: Entity Wizard generate incorrect ManyToMany relationship mapping
Status: RESOLVED INVALID
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 6.x
Hardware: All All
: P1 blocker (vote)
Assignee: Andrei Badea
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-17 22:47 UTC by Nam Nguyen
Modified: 2007-04-18 16:18 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
sample database (477.82 KB, text/xml)
2007-04-18 09:48 UTC, Nam Nguyen
Details
database (630.34 KB, application/octet-stream)
2007-04-18 15:55 UTC, Nam Nguyen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nam Nguyen 2007-04-17 22:47:28 UTC
- Invoke New Entity from Database wizard, connecting to sample javaDB database.
- Select all tables for entity generation, make sure table
CUSTOMER_PURCHASE_ORDER is included.
- The wizard generates a separate entity class for the above association table.  

IMO, the right mapping should be:
(1) Annotate @ManyToMany on both fields: Customer.purchaseOrderCollection and
PurchaseOrder.customerCollection.
(2) Annotate @JointTable(name="CUSTOMER_PURCHASE_ORDER") on either of the above
fields, whichever is decided as owning entity.
There should be no entity class for association tables.
Comment 1 Nam Nguyen 2007-04-17 22:58:06 UTC
I think this is high-profile feature and the fix should make it to M9.
Comment 2 Andrei Badea 2007-04-18 09:10:54 UTC
Which sample database do you mean? There is no CUSTOMER_PURCHASE_ORDER table in
the sample database registered by the Java DB module.
Comment 3 Nam Nguyen 2007-04-18 09:47:06 UTC
I am attaching my sample db.  Maybe I did the change a month back.  But I did
clean build frequently and I recently reinstalled glassfish.  So where is the
dirty database coming from?
Comment 4 Nam Nguyen 2007-04-18 09:48:21 UTC
Created attachment 41141 [details]
sample database
Comment 5 Andrei Badea 2007-04-18 10:25:10 UTC
Reinstalling GlassFish never rewrites an existing sample database. The database
is also stored outside the userdir, so you don't get a new one when you wipe
your userdir.
Comment 6 Andrei Badea 2007-04-18 10:50:57 UTC
Please attach the SQL script used to create the C_P_O table, or at least the
zipped-up database directory. Why do you have four foreign keys in C_P_O? This
makes the wizard think it's not a join table (which is expected to have two
foreign keys).
Comment 7 Nam Nguyen 2007-04-18 15:30:57 UTC
Where should i look for the database dir?  Please tell me the path.
Comment 8 Andrei Badea 2007-04-18 15:45:03 UTC
It's in Tools - Options - Advanced Options - Server and External Tool Settings -
Java DB Database - Database Location. Usually the path is $HOME/.netbeans-derby.
Comment 9 Nam Nguyen 2007-04-18 15:55:43 UTC
Created attachment 41179 [details]
database
Comment 10 Nam Nguyen 2007-04-18 16:06:47 UTC
I drop the duplicate constraints and the code gen does produce correct m-n
mapping.  Sorry for false alarm.
Comment 11 Nam Nguyen 2007-04-18 16:18:43 UTC
BTW, I can't think of any use cases that justify additional constraints or
duplicate constraints on the association table.  But if you want to handle this
corner, it is certainly of much less priority.