jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Signup
Mod4j: Modeling for Java using Domain Specific Languages
  • Mod4j: Modeling for Java using Domain Specific Languages
  • MODFORJ-31

equals method in domain objects

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0.0
  • Fix Version/s: 1.0.0
  • Component/s: DSL for Business Domain
  • Labels:
    None
  • Number of attachments :
    0

Description

During the presentation yesterday (25-09-2008) there was a quick discussion about generating an equals method (along with toString, hashCode and more).

If its decided an equals method must be created (you can still create a stub) then please read this article:
http://cwmaier.blogspot.com/2007/07/liskov-substitution-principle-equals.html

It states the current implementations of Eclipse and MyEclipse (which can both generate 'equals' methods for you) do it wrong to some degree.

Summary:

Eclipse does this:
if (getClass() != obj.getClass()) return false;

This goes wrong with proxies, because getClass isn't the same in a proxy as the concrete (super) class.

MyEclipse solved this with generating this:
if (!(obj instanceof MyClass)) return false;

But... MyEclipse goes on generating comparisons for (some? all public?) fields in the object, for example:
if (!name.equals(other.name)) return false;

This doesn't work for Hibernate proxies, they don't have the time to (lazy) load the fields, you should instead use:
if (!name.equals(other.getName())) return false;

So if we combine this knowledge I think we can generate valid 'equals' methods in Mod4J. You start out by comparing the class the way MyEclipse does, and then generate comparisons for all fields mapped to the database (which we know from the model). These fields combined represent the state of a domain-object.

Issue Links

is depended upon by

Improvement - An improvement or enhancement to an existing feature or task. MODFORJ-69 Ordered association lacks method to use the ordening.

  • Major - Major loss of function.
  • Resolved - A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.
is related to

Improvement - An improvement or enhancement to an existing feature or task. MODFORJ-49 Generate 'toString()', 'hashCode()' and 'equals()' methods into the domain classes.

  • Major - Major loss of function.
  • Resolved - A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.

Activity

  • All
  • Comments
  • Work Log
  • History
  • Activity
There are no comments yet on this issue.

People

  • Assignee:
    Eric Jan Malotaux
    Reporter:
    Johan Vogelzang
Vote (0)
Watch (0)

Dates

  • Created:
    19/Feb/09 8:42 AM
    Updated:
    26/Feb/09 6:38 AM
    Resolved:
    24/Feb/09 10:38 AM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.