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

Summary: Entity from Database, duplicate field generation
Product: javaee Reporter: martin_suter <martin_suter>
Component: PersistenceAssignee: Andrei Badea <abadea>
Status: VERIFIED FIXED    
Severity: blocker CC: blaha
Priority: P2 Keywords: REGRESSION
Version: 6.x   
Hardware: Other   
OS: All   
Issue Type: DEFECT Exception Reporter:
Attachments: SQL script for reproducing the issue

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