I have trouble writing correct equals()
function in POJOs to use with hierbante. My main problem is with List's.
For example I have an Entity Request
which has a list of Person
s
@ManyToMany(cascade = CascadeType.ALL)
@LazyCollection(LazyCollectionOption.FALSE)
@JoinTable(name = "JOIN_TABLE_REQUEST_TO_PERSON", joinColumns =
@JoinColumn(name = "REQUEST_ID"), inverseJoinColumns =
@JoinColumn(name = "PERSON_ID"))
private List<Person> proxyList = new ArrayList<Person>();
Now I use Netbeans 7.3 generated equals()
and for this list it generates me the code:
...
if (this.proxyList != other.proxyList && (this.proxyList == null || !this.proxyList.equals(other.proxyList))) {
return false;
}
...
However this does not work correctly when I add Persons to the list. I had to change this code to:
...
if (!this.proxyList.containsAll(proxyList)) {
return false;
}
...
How should it be done correctly? Do you have any other best practices for writing equals for hibernate?