[forge-issues] [JBoss JIRA] (FORGE-386) PersistencePlugin needs to generate hashCode and equals based on Id
Richard Kennard (Commented) (JIRA)
jira-events at lists.jboss.org
Sun Dec 4 06:59:40 EST 2011
[ https://issues.jboss.org/browse/FORGE-386?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12647848#comment-12647848 ]
Richard Kennard commented on FORGE-386:
---------------------------------------
Perfect for my needs! Thanks!
> 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
More information about the forge-issues
mailing list