0

enter image description here

In our project we are using Spring with Hibernate and we are using other team jars as dependent jars to fetch data from oracle data base.

We are getting duplicate records even though we implemented equals() and hashCode() methods in model classes and we are storing these object in HashSet. I am strange why set is allowing duplicate objects here. Even though hashCode() and equals() method is overridden ?.

If you observe the screen shot modcount size is different and table size is different

2
  • 4
    Please provide your code. It will help to understand the issue. Commented Mar 6, 2018 at 10:21
  • 2
    Btw, only because you implemented equals and hashCode does not mean you can't have duplicates. Commented Mar 6, 2018 at 10:26

1 Answer 1

3
  • remove hashCode() or equals() from your class

  • if you are Override equals and hashcode methods in your class, then equal objects return the same hashCode.. the HashSet is not allowed the same hashcode because HashSet validating duplicate in based on hashCode, so the solution for you: you can remove hashCode() or equals() from your class

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.