Bug 293189 - [ENTITY GEN] getters do not reflect camel case of class names
Summary: [ENTITY GEN] getters do not reflect camel case of class names
Status: NEW
Alias: None
Product: Dali JPA Tools
Classification: WebTools
Component: JPA (show other bugs)
Version: 2.2.1   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: Future   Edit
Assignee: Neil Hauge CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2009-10-23 11:23 EDT by Shaun Smith CLA
Modified: 2013-10-08 11:09 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shaun Smith CLA 2009-10-23 11:23:20 EDT
When generating entities from a database with EMPLOYEE and PHONENUMBERS tables with a OneToMany from EMPLOYEE to PHONENUMBERS, the default Entity names are Employee and Phonenumbers.  If the default is overridden and Phonenumbers is renamed PhoneNumbers, the Entities are generated with the correct names.  However the getter for PhoneNumbers on Employee is generated as getPhonenumbers() and not, as expected, getPhoneNumbers().  The getter generation does not correctly reflect the camel casing of the target Entity and should.
Comment 1 Neil Hauge CLA 2010-01-08 16:01:19 EST
Targeting to head based on non-major severity of this issue.
Comment 2 Danny Ju CLA 2010-04-20 18:54:43 EDT
I am not able to reproduce.
The generated getter/setter code does preserve the camel case: 

	//bi-directional many-to-one association to Phonenumber
	@OneToMany(mappedBy="employee")
	private Set<Phonenumber> phoneNumbers;
	public Set<Phonenumber> getPhoneNumbers() {
		return this.phoneNumbers;
	}


Tested on Oracle with following SQL: 


drop table EMPLOYEES
create table EMPLOYEES
  (NAME VARCHAR(100) not null);

alter table EMPLOYEES
  add constraint PK_EE primary key (NAME);


drop table PHONENUMBER
create table PHONENUMBER
  (NO VARCHAR(100) not null,
   EMPLOYEE_NAME VARCHAR(100) not null);

alter table PHONENUMBER
  add constraint PK_SURVEY primary key (NO);

ALTER TABLE PHONENUMBER
 add constraint EMPLOYEE_NAME
 FOREIGN KEY (EMPLOYEE_NAME) 
  REFERENCES EMPLOYEES (NAME);
Comment 3 Danny Ju CLA 2010-04-20 20:04:43 EDT
Shaun, can you try again and let me know if still reproduced?
Comment 4 Karen Butzke CLA 2010-04-21 11:45:11 EDT
I can reproduce this Danny. I created tables on a derby database.  Then generated entities and renamed the default entity name Phonenumber to PhoneNumber. 

Employee was generated with:

	private Set<PhoneNumber> phonenumbers;

	public Set<PhoneNumber> getPhonenumbers() {
		return this.phonenumbers;
	}

	public void setPhonenumbers(Set<PhoneNumber> phonenumbers) {
		this.phonenumbers = phonenumbers;
	}

I don't understand the code that you have posted.  How is the class name Phonenumber with a lower case 'n' and the field/getter/setter have a capitalized 'N' for Number?  That looks like the opposite problem and I don't see how that could happen.
Comment 5 Shaun Smith CLA 2010-04-21 12:50:55 EDT
I just stumbled across what I think is really going on here.  Both Karen and I think that changing the name of an Entity from Phonenumber to PhoneNumber should change the getter/setter on Employee.  But the getter/setter is based on the Employee.phonenumber property name which does not seem to be affected by the class rename.  So the real "bug" here is that the property of Employee is not changed Employee.phoneNumber when the default Phonenumber class name is changed to PhoneNumber.  If this were to happen the getter/setter would generate fine.
Comment 6 Karen Butzke CLA 2010-04-21 13:00:52 EDT
Oh duh, I *knew* there was something fishy going on, thanks for clearing that up Shaun.  So that complicates things further since the 'phonenumbers' property is defined on an earlier page of the entity gen wizard than the entity name.  Might be weird to have the wizard modify that after already completing that wizard page.
Comment 7 Karen Butzke CLA 2010-04-21 13:30:35 EDT
It appears that we need to define the entity class name before the table associations so that those property names can be dependent on the entity class name.  Possibly we could move the 4th wizard page to the 2nd position.  Or move the 2nd wizard page to the end.  Not sure about changing up the flow this late in the cycle.  

Or maybe class names should be defined separately. In our original entity gen wizard the class names were defined where you selected the tables.  It was a checkbox table with 2 columns : 'table' and 'class name'.  The class name is probably something that is change a lot and it's on the last wizard page.
Comment 8 Danny Ju CLA 2010-04-21 13:42:48 EDT
Right, that was what I did: to change  getter/setter method names of an
OTM,OTO association, I change the property name of the association, not the
target Entity name.   

Changing association property name based on target entity name is problematic:
since the target entity may be referenced by different entities. User may
actually want to uses a more meaningful and possibly different property name to
represent the target entity within each context.

Moving the 4th wizard page to the 2nd position is not a trivial change.
I need revisit the existing code to see what the impact will be.
Comment 9 Neil Hauge CLA 2010-04-26 09:59:12 EDT
It looks like this is going to be more of a functional change than a bug fix.  As a result, I'm going to defer this to the next release.
Comment 10 Neil Hauge CLA 2011-07-01 16:26:11 EDT
Moving JPA specific bugs to new JPA component in bugzilla.