Details
-
Type:
Improvement
-
Status:
Resolved
-
Priority:
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 :
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
-
MODFORJ-69
Ordered association lacks method to use the ordening.
-
- is related to
-
MODFORJ-49
Generate 'toString()', 'hashCode()' and 'equals()' methods into the domain classes.
-