[
https://issues.jboss.org/browse/FORGE-386?page=com.atlassian.jira.plugin....
]
Richard Kennard commented on FORGE-386:
---------------------------------------
Thanks for doing this!
But the version implemented is broken, I think. It basically says 'all unsaved
entities will have the same hashCode' and 'all unsaved entities are
equivalent'. It may even NullPointer?
I would rather it delegate to super.hashCode and super.equals if ( id == null ). The same
as my version above.
But up to you.
PersistencePlugin needs to generate hashCode and equals based on Id
-------------------------------------------------------------------
Key: FORGE-386
URL:
https://issues.jboss.org/browse/FORGE-386
Project: Forge
Issue Type: Enhancement
Reporter: Richard Kennard
Assignee: Lincoln Baxter III
Fix For: 1.0.0.Beta4
Domain classes generated by Forge need to override hashCode/equals if they are to be
useful in a UI (among other places). This is hard to do if we know nothing about the
semantics of the class, but the PersistencePlugin *does* know something: namely, the Id.
The following implementation would suffice for my purposes:
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
if (id != null) {
return id.equals(((Employer) that).id);
}
return super.equals(that);
}
@Override
public int hashCode() {
if (id != null) {
return id.hashCode();
}
return super.hashCode();
}
But I'm happy for other implementations too.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see:
http://www.atlassian.com/software/jira