6 Replies Latest reply: Sep 16, 2010 10:32 AM by 843793 RSS

    Set allowing to add duplicate objects

      I faced this problem when populating the entities through hibernate . I have two entites A & B (Both mapped to their respective tables)

      I need to store distinct code values from A (mapped to table ) . In order to avoid duplicates I used Set . Set works fine if I store only from A. Say Entity B has reference to A.

      class B
      private A object;


      Now already I have populated my Set from table A. Now the values which are not present in this collection needs to be stored. The same object (who has same identifier value) added by B().getObject() returns hashCode different from that of object returned from A. Both has same data.

      Could some one explain why there are difference in has values and it allows to add duplicates ?