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

Cascading the one-to-one merge operation

The CascadeType.MERGE is inherited from the CascadeType.ALL setting, so we only have to merge the Info entity and the associated InfoDetails is merged as well:

Info info = entityManager.find(Info.class, 1L);
info.getDetails().setVisible(true);
entityManager.merge(info);

The merge operation generates the following output:

UPDATE infodetails SET
created_on = '2016-01-03 16:20:53.874', visible = true
WHERE id = 1
UPDATE info SET
NAME = 'Wildfly Book Info'
WHERE id = 1