Skip to:
Hibernate don't delete the orphan entries with OneToOne even after set to null
@Entitypublic class Foo{@Idprivate long foo_id;
private String name;
@OneToOne(mappedBy = "foo", orphanRemoval = true)private FooProperties fooProperties;}
@Entitypublic class FooProperties{
@Idprivate long fp_id;
private String phoneNumber;
@OneToOne@JoinColumn(name = "foo_id", nullable = false)private Foo foo;}
and if I do - Foo foo = entityManager.find(Foo.class, fooId);foo.getFooProperties.setFoo(null);foo.setFooProperties(new FooProperties("xxx-xxx-xxx"));entityManager.merge(foo);
its not deleting the FooProperties
described the issue @ http://stackoverflow.com/questions/5389561/referential-integrity-with-one-to-one-using-hibernate
Hibernate don't delete the orphan entries with OneToOne even after set to null
@Entity
public class Foo{
@Id
private long foo_id;
private String name;
@OneToOne(mappedBy = "foo", orphanRemoval = true)
private FooProperties fooProperties;
}
@Entity
public class FooProperties{
@Id
private long fp_id;
private String phoneNumber;
@OneToOne
@JoinColumn(name = "foo_id", nullable = false)
private Foo foo;
}
and if I do -
Foo foo = entityManager.find(Foo.class, fooId);
foo.getFooProperties.setFoo(null);
foo.setFooProperties(new FooProperties("xxx-xxx-xxx"));
entityManager.merge(foo);
its not deleting the FooProperties