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 123212 - Entity from Database, duplicate field generation
Summary: Entity from Database, duplicate field generation
Status: VERIFIED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 6.x
Hardware: Other All
: P2 blocker (vote)
Assignee: Andrei Badea
URL:
Keywords: REGRESSION
Depends on:
Blocks:
 
Reported: 2007-12-02 09:31 UTC by martin_suter
Modified: 2008-02-20 18:16 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
SQL script for reproducing the issue (1.17 KB, text/plain)
2007-12-05 11:13 UTC, Andrei Badea
Details

Note You need to log in before you can comment on or make changes to this bug.
Description martin_suter 2007-12-02 09:31:42 UTC
In the case of a many-to-many relationship referring to only one table

1. table category
-----------------
id
name ...

2. table cat_relation
---------------------
id (refers to category->id)
parent_id (refers to category->id)


there will be 2 identical fields generated in the ejb

@ManyToMany
private Collection<Category> categoryCollection;
@ManyToMany(mappedBy = "categoryCollection")
private Collection<Category> categoryCollection;

Netbeans 5.5.1 handled this by adding an index to the following fields (categoryCollection1,categoryCollection2 etc)
Comment 1 Andrei Badea 2007-12-03 13:29:57 UTC
Sorry, I can't reproduce this. When CAT_RELATION.ID was a primary key, this is what was generated:

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "parentId")
    private Collection<CatRelation> catRelationCollection;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "category")
    private CatRelation catRelation;

When it was not a primary key, the following was generated:

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "parentId")
    private Collection<CatRelation> catRelationCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "id")
    private Collection<CatRelation> catRelationCollection1;

Please attach a simple schemas that you can reproduce the issue with in NetBeans 6.0. Thanks.
Comment 2 Andrei Badea 2007-12-05 11:13:42 UTC
Created attachment 53889 [details]
SQL script for reproducing the issue
Comment 3 Andrei Badea 2007-12-05 11:18:04 UTC
Reproducible using the attached SQL script, and it is indeed a regression (5.5 behaves as stated by reporter in desc1).
Comment 4 Andrei Badea 2008-01-21 18:12:59 UTC
Fixed.

Checking in src/org/netbeans/modules/j2ee/persistence/entitygenerator/DbSchemaEjbGenerator.java;
/cvs/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/entitygenerator/DbSchemaEjbGenerator.java,v  <-- 
DbSchemaEjbGenerator.java
new revision: 1.10; previous revision: 1.9
done
Comment 5 Petr Blaha 2008-01-31 13:14:27 UTC
Reporter, can you please verify the bug in the latest daily build? Thanks
Comment 6 Jindrich Sedek 2008-01-31 15:20:59 UTC
verified.
correct fields are generated - separated by an index
NetBeans IDE Dev (Build 200801310006)
Comment 7 pgebauer 2008-02-06 19:01:58 UTC
The fix has been ported into the release601_fixes branch.

Checking in DbSchemaEjbGenerator.java;
/cvs/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/entitygenerator/Attic/DbSchemaEjbGenerator.java,v  <-- 
DbSchemaEjbGenerator.java
new revision: 1.9.10.1; previous revision: 1.9
done