I have tasked to prepare a quote search screen. I have referred to an Oracle view to create quote model. As there is no id column in the view table, I prefer to use composite id using @IdClass annotation via quoteId.class. I override hashCode and equals method on both model. quoteId equals & hashcode returns a combination of all fields and quote hashcode & equals simply just compare this.quoteNo field in the model.
Quote model:
@Override
public int hashCode()
{
return new HashCodeBuilder(17,37)
.append(quoteNo)
.toHashCode();
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj)
{
final quoteModel other = (quoteModel ) obj;
return new EqualsBuilder().appendSuper(super.equals(other))
.append(quoteNo, other.quoteNo).isEquals();
}
And when I need unique items I was just accessing via:
uniqueQuoteResults = new ArrayList<Quote>(
new LinkedHashSet<Quote>(fullQuoteResults));
But when I start using idClass my linkedHashSet has all items even their quote number same. Am I missing any other implementation to proof each item uniqueness via quote no field(comparable, comparator)? If I trace uniqueQuoteResult list items values all of them has same quote number.
Edit Note: I have changed my way to using apache library HashCodeBuilder and EqualsBuilder support but problem stays same. I am afraid of idClass hashcode is getting effective for linkedhashset