Hibernate version: 3
Name and version of the database you are using: FireFox
Hi. This seems like a simple problem but I can't find it specifically in the forums and guides:
I have written a Dao's for the standard stuff, and a Hibernate Dao test suite. In one of the tests I am retrieving a currency rate, updating the rate to something else, saving it, retrieving it again to a different local var and testing that the first one I retrieved equls() the second one. It should be because the souce and target currencies are the same, and the start and end dates of the currency rates are the same. Only the fx rate has been changed. However the equality test fails when CurrencyRate tests the two source currencies. It fails in the o.getClass() != this.getClass() part of the Currency equals() method, because one is a Currency object and the other is one of those Currency$$EnhancerByCGILIB$$... objects.
I am using accessors in CurrencyRate to avoid lazy loading problems. I can't think what else to do to fix this. Anyone help?
Salient atributes and equals method for Currency:
private String currencyCode;
private String description;
public boolean equals( Object o )
{
if ( this == o ) return true;
if ( o == null || o.getClass() != this.getClass() ) return false;
final Currency currency = (Currency) o;
if ( this.getCurrencyCode() != null ?
!this.getCurrencyCode().equals( currency.getCurrencyCode() ) :
currency.getCurrencyCode() != null ) return false;
return true;
}
Salient attributes and equals method for CurrencyRate:
private DateMidnight startDate;
private DateTime endDate;
private Currency sourceCurrency;
private Currency targetCurrency;
private BigDecimal rate;
public boolean equals( Object o )
{
if ( this == o ) return true;
if ( o == null || o.getClass() != this.getClass() ) return false;
final CurrencyRate currencyRate = (CurrencyRate) o;
if ( !this.getStartDate().equals( currencyRate.getStartDate() ) ) return false;
if ( !this.getEndDate().equals( currencyRate.getEndDate() ) ) return false;
if ( !this.getSourceCurrency().equals( currencyRate.getSourceCurrency() ) ) return false;
if ( !this.getTargetCurrency().equals( currencyRate.getTargetCurrency() ) ) return false;
return true;
}
Hibernate mapping for CurrencyRate is:
<class name="CurrencyRate" table="CURRENCY_RATE" lazy="true">
<id name="objectId" column="CURRENCY_RATE_ID" type="long">
<generator class="hilo">
<param name="table">OBJECT_ID</param>
<param name="column">next_value</param>
<param name="max_lo">100</param>
</generator>
</id>
<property name="startDate" column="START_DATE" type="com.ilign.ppm.common.PersistentDateMidnight"/>
<property name="endDate" column="END_DATE" type="com.ilign.ppm.common.PersistentDateTime"/>
<property name="rate" column="rate" type="big_decimal"/>
<many-to-one name="sourceCurrency" class="Currency" column="SOURCE_CURRENCY_ID" cascade="none"/>
<many-to-one name="targetCurrency" class="Currency" column="TARGET_CURRENCY_ID" cascade="none"/>
</class>
and for Currency is:
<class name="Currency" table="CURRENCY" lazy="true">
<id name="objectId" column="CURRENCY_ID" type="long">
<generator class="hilo">
<param name="table">OBJECT_ID</param>
<param name="column">next_value</param>
<param name="max_lo">100</param>
</generator>
</id>
<property name="currencyCode" column="CURRENCY_CODE" type="string"/>
<property name="description" column="DESCRIPTION" type="string"/>
</class>
|