farzad wrote:
I don't see why it shouldn't be. One set has enough information for HB so that it know how to persist the relation. Are you having a problem with it?
Yes, the problem is we want the relationship to be bi-directional.
Code:
public class Apple {
private Set<Apple> apples = new HashSet<Apple>();
public Set<Apple> getApples() {
return apples;
}
public void setApples(Set<Apple> apples) {
this.apples = apples;
}
}
So we have the following test, something like this :
Code:
Apple apple1 = new Apple();
Apple apple2 = new Apple();
session.save(apple1);
session.save(apple2);
apple1.getApples().add(apple2);
session.update(apple1);
session.evict(apple1);
session.evict(apple2);
apple1 = session.load(Apple.class, apple1.getId);
apple2 = session.load(Apple.class, apple2.getId);
assertTrue(apple1.getApples.contains(apple2));
assertTrue(apple2.getApples.contains(apple1)); // WE WANT THIS TO WORK BUT IT DOESN'T