many-to-one set.add() already existing items are added

Description

following schematic testcase:

public class A {
...
private Set<B> mySetOfBs = new HashSet<B>();
...
@OneToMany(mappedBy = ...)
@JoinColumns(...)
public Set<B> getMySetOfBs() { ... }
...
}

public class B {
private PrimaryKeyB pk;
...
public boolean equals(...) { ... }
public int hashCode() { ... }
}

public class PrimaryKeyB {
public boolean equals(...) { ... }
public int hashCode() { ... }
}

The call of objectOfA.getMySetOfBs().add(alreadyExistingB) returns with true.
JDK api-doc: "true if this set did not already contain the specified element."

I simply get the first element of the set to initialize the object 'alreadyExistingB' and added it to the set-of-bs.

Activity

Show:

Brett Meyer December 18, 2013 at 9:03 PM

These types of questions are best started in the user forums: https://forum.hibernate.org/viewforum.php?f=1. Please open JIRA tickets only when a concise, reproducible issue is identified. Thanks!

Rejected

Details

Assignee

Reporter

Affects versions

Priority

Created April 13, 2006 at 11:45 AM
Updated December 18, 2013 at 9:03 PM
Resolved December 18, 2013 at 9:03 PM