Vinu wrote:
I overcame this problem by returning some random number if the featureId is null
You should never return a random number for the hashCode. Coz semantics of hashCode also says that:
Quote:
Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
So using random number will go against this rule. I think the solution would be to use the un-saved id value to generate the hashCode in this case. Which means in the mapping you have specified:
Quote:
<id name="featureId" column="F_ID" type="java.lang.Integer" unsaved-value="0">
<generator class=".....">......</generator>
</id>
Then use 0 for generating hashCode if the object is unsaved. Like:
Code:
public int hashCode() {
if(getFeautreId() != null)
return new Long(getFeatureId()).hashCode();
else
return new (Long(0)).hashCode();
}
But Vinu, I am having a doubt here. Your ServiceModelVO to FeatureModelVO relation is MTO. So how come the result will contain non-unique members? Coz one FeatureModelVO would be related to one ServiceModelVO only once !!