[
http://opensource.atlassian.com/projects/hibernate/browse/HBX-1116?page=c...
]
Magnus Jungsbluth commented on HBX-1116:
----------------------------------------
The code-generation for equals treats the natural-id properties as if they had the
"use-in-equals" meta-attribute while the code-generation of hashCode()
explicitly requires the meta-attribute.
To reproduce:
hbm.xml:
------------
{code}
<natural-id>
<property name="identificationNo"
type="java.lang.Long">
<column name="SOME_COLUMN" precision="10"
scale="0" />
</property>
</natural-id>
{code}
Generated equals:
-------------------------
{code}
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( (other == null ) ) return false;
if ( !(other instanceof BaseContainerType) ) return false;
BaseContainerType castOther = ( BaseContainerType ) other;
return ( (this.getIdentificationNo()==castOther.getIdentificationNo()) || (
this.getIdentificationNo()!=null && castOther.getIdentificationNo()!=null
&& this.getIdentificationNo().equals(castOther.getIdentificationNo()) ) );
}
{code}
Generated hashCode:
-------------------------------
{code}
public int hashCode() {
int result = 17;
//endless lines of whitespace (one for every property)
//missing code for "identificationNo"
return result;
}
{code}
Generated hashCode() is inconsistent with equals() when using
natural-id tag
----------------------------------------------------------------------------
Key: HBX-1116
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HBX-1116
Project: Hibernate Tools
Issue Type: Patch
Affects Versions: 3.2.4.GA
Environment: hibernate tools revision 16240
Reporter: Magnus Jungsbluth
Priority: Minor
Attachments: hbm2java_hashCode_equals.patch
when using a natural-id tag in a hbm.xml file, the pojo's generated equals method
uses the natural-id properties while the hashcode implementation requires an additional
meta-attribute
the included patch uses the same check as in the equals generation in
basicpojoclass.java
additionally the template has been changed to only iterate over equalshashcode properties
which reduces unnecessary blank lines in the hashcode implementation
the template also contained wrongly indented lines
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira