Mastering Java EE Development with WildFly
上QQ阅读APP看书,第一时间看更新

The one-to-one delete orphan cascading operation

If a child entity is separated from its parent, the child foreign key will take the NULL value. If we really want to remove the child row, we must use the orphan removal support:

Info info = (Info)entityManager.get(Info.class, 1L);
info.removeDetails();

Using the orphan removal, this operation will be generated:

delete from InfoDetails where id = 1