Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 388568 - JPA Entity Gen should generate One to Many Bi Directional Methods
Summary: JPA Entity Gen should generate One to Many Bi Directional Methods
Status: RESOLVED FIXED
Alias: None
Product: Dali JPA Tools
Classification: WebTools
Component: JPA (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 3.2.2   Edit
Assignee: Neil Hauge CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 137581 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-08-31 13:17 EDT by Chris Stodden CLA
Modified: 2013-05-21 14:34 EDT (History)
4 users (show)

See Also:
neil.hauge: review+


Attachments
Proposed Patch (13.65 KB, patch)
2012-09-05 18:38 EDT, Chris Stodden CLA
no flags Details | Diff
Updated Patch (13.61 KB, patch)
2012-09-11 12:23 EDT, Chris Stodden CLA
no flags Details | Diff
Updated Patch With Singularise (14.32 KB, patch)
2013-01-03 18:22 EST, Chris Stodden CLA
neil.hauge: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Stodden CLA 2012-08-31 13:17:53 EDT
Dali JPA Entity Gen.

Given the Field Value:

    //bi-directional many-to-one association to Employee
    @OneToMany(mappedBy="employee")
    private Set<Employee> employees;


Generate Additional Methods:
    public Employee addEmployees(Employee employees) {
        getEmployees().add(employees);
        employees.setEmployee(this);
        return employees;
    }

    public Employee removeEmployees(Employee employees) {
        getEmployees().remove(employees);
        employees.setEmployee(null);
        return employees;

    }

How things are derived in the template: 

-Condition: given that the cardinality is one to many and bi-directional.

-Where getEmployees is derived from the AssociationRole Property Name.

-Where Set or List extend Collection: getEmployees: add, remove

-Where the Method Parameter is the AssociationRole.ReferencedTable.ClassName

-Where the method parameter variable get/set method is the AssociationRole.OppositeRole.PropertyName.
Comment 1 Chris Stodden CLA 2012-08-31 13:19:05 EDT
Eclipse Version: 3.7.2 Build id: M20120208-0800
Comment 2 Chris Stodden CLA 2012-09-05 18:38:02 EDT
Created attachment 220765 [details]
Proposed Patch
Comment 3 Chris Stodden CLA 2012-09-11 12:23:18 EDT
Created attachment 220943 [details]
Updated Patch

Updated patch based off of webtools dali tag v201205020001.
Comment 4 Neil Hauge CLA 2012-12-07 14:30:15 EST
Chris...was just taking a look at this patch for SR2.  One useful change would be to "singularise" the collection name so you could end up with names like, "addEmployee()" and "removeEmployee()".  Take a look at org.eclipse.jpt.jpa.gen.internal.util.StringUtil.singularise().
Comment 5 Neil Hauge CLA 2012-12-07 14:38:37 EST
*** Bug 137581 has been marked as a duplicate of this bug. ***
Comment 6 Chris Stodden CLA 2013-01-03 18:22:24 EST
Created attachment 225194 [details]
Updated Patch With Singularise

This updated patch uses singularise for the method name and var name creation.
Comment 7 Neil Hauge CLA 2013-01-04 17:02:21 EST
Testing of the patch has gone well, some minor changes for generated code formatting.  Waiting for this week's build declare to commit.
Comment 8 Neil Hauge CLA 2013-01-04 18:22:29 EST
Committed to Juno SR2 maintenance and Master branches.