Senior |
|
Joined: Fri May 14, 2004 9:37 am Posts: 122 Location: Cologne, Germany
|
Hi ,
perhaps I', totally wrong but when I use the Equals Method generated by HibernateTools then I always get true as Return-Value.
Here's a mapping example for this behaviour this occures for all Pojo's
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="de.xcom.provimax.pojo.Schnittstelle" table="T_SCHNITTSTELLE" >
<id name="Id" type="long">
<column name="SSTID" scale="0" />
<generator class="native">
<param name="sequence">T_SCHNITTSTELLE_SEQ</param>
</generator>
</id>
<property name="Name" type="string">
<meta attribute="use-in-equals">true</meta>
<column name="NAME" length="40" />
</property>
<property name="Classname" type="string">
<meta attribute="use-in-equals">true</meta>
<column name="CLASSNAME" />
</property>
<property name="Importdirectory" type="string">
<meta attribute="use-in-equals">true</meta>
<column name="IMPORTDIRECTORY" />
</property>
<property name="Tablename" type="string">
<meta attribute="use-in-equals">true</meta>
<column name="TABLENAME" />
</property>
<property name="Procedurename" type="string">
<meta attribute="use-in-equals">true</meta>
<column name="PROCEDURENAME" />
</property>
<property name="Deleted" type="boolean">
<meta attribute="use-in-equals">true</meta>
<column name="DELETED" precision="1" scale="0" not-null="true" />
</property>
<property name="Editable" type="boolean">
<meta attribute="use-in-equals">true</meta>
<column name="EDITABLE" precision="1" scale="0" />
</property>
<property name="Typ" type="string">
<meta attribute="use-in-equals">true</meta>
<column name="TYP" length="20" />
</property>
<set name="Depots" inverse="true">
<key>
<column name="SSTID" precision="10" scale="0" />
</key>
<one-to-many class="de.xcom.provimax.pojo.Depot" />
</set>
<set name="Konditionen" inverse="true">
<key>
<column name="SSTID" precision="10" scale="0" />
</key>
<one-to-many class="de.xcom.provimax.pojo.Kondition" />
</set>
<set name="SstFiles" inverse="true">
<key>
<column name="SSTID" scale="0" />
</key>
<one-to-many class="de.xcom.provimax.pojo.SstFiles" />
</set>
</class>
</hibernate-mapping>
Equals and hashCode Method for these Pojo:
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( (other == null ) ) return false;
if ( !(other instanceof Schnittstelle) ) return false;
Schnittstelle castOther = ( Schnittstelle ) other;
return (this.getName()==castOther.getName()) || ( this.getName()!=null && castOther.getName()!=null && this.getName().equals(castOther.getName()) )
&& (this.getClassname()==castOther.getClassname()) || ( this.getClassname()!=null && castOther.getClassname()!=null && this.getClassname().equals(castOther.getClassname()) )
&& (this.getImportdirectory()==castOther.getImportdirectory()) || ( this.getImportdirectory()!=null && castOther.getImportdirectory()!=null && this.getImportdirectory().equals(castOther.getImportdirectory()) )
&& (this.getTablename()==castOther.getTablename()) || ( this.getTablename()!=null && castOther.getTablename()!=null && this.getTablename().equals(castOther.getTablename()) )
&& (this.getProcedurename()==castOther.getProcedurename()) || ( this.getProcedurename()!=null && castOther.getProcedurename()!=null && this.getProcedurename().equals(castOther.getProcedurename()) )
&& (this.getDeleted()==castOther.getDeleted()) || ( this.getDeleted()!=null && castOther.getDeleted()!=null && this.getDeleted().equals(castOther.getDeleted()) )
&& (this.getEditable()==castOther.getEditable()) || ( this.getEditable()!=null && castOther.getEditable()!=null && this.getEditable().equals(castOther.getEditable()) )
&& (this.getTyp()==castOther.getTyp()) || ( this.getTyp()!=null && castOther.getTyp()!=null && this.getTyp().equals(castOther.getTyp()) );
}
public int hashCode() {
int result = 17;
result = 37 * result + ( getName() == null ? 0 : this.getName().hashCode() );
result = 37 * result + ( getClassname() == null ? 0 : this.getClassname().hashCode() );
result = 37 * result + ( getImportdirectory() == null ? 0 : this.getImportdirectory().hashCode() );
result = 37 * result + ( getTablename() == null ? 0 : this.getTablename().hashCode() );
result = 37 * result + ( getProcedurename() == null ? 0 : this.getProcedurename().hashCode() );
result = 37 * result + this.getDeleted().hashCode();
result = 37 * result + ( getEditable() == null ? 0 : this.getEditable().hashCode() );
result = 37 * result + ( getTyp() == null ? 0 : this.getTyp().hashCode() );
return result;
}
IMHO the Code should look like this:
((this.getName()==castOther.getName()) || ( this.getName()!=null && castOther.getName()!=null && this.getName().equals(castOther.getName()) ) ) && .........
any other suggestions???
regards
_________________ regards
Olaf
vote if it helped
|
|