简体   繁体   English

如何还原具有ManyToOne关系的JPA实体

[英]How to restore an JPA Entity with ManyToOne relations

I have an JPA entity (Person) with ManyToOne relation to an other entity (Addresses). 我有一个JPA实体(人),该实体具有与另一个实体(地址)的ManyToOne关系。 Before an object may be used by the system, this one has to be approved by an supervisor. 在系统使用某个对象之前,必须先由主管批准。 I store the original entity as a byte[] and make changes to the "working" entity and store it do the database. 我将原始实体存储为byte [],并更改“工作”实体并将其存储到数据库中。 If this changes would not be approved I have to restore the original state. 如果无法批准此更改,则必须恢复原始状态。 So I convert the stored original from the byte[] and merge it using entity manager to the database. 因此,我从byte []转换了存储的原始文件,然后使用实体管理器将其合并到数据库中。 All works fine, but if an new Address entity has been added to the "working" Person, this one is not removed from the database after merging the restored original. 一切正常,但是如果将新的地址实体添加到“工作中的”人员中,则在合并还原的原始对象之后,不会从数据库中删除该地址实体。 I know why it is so, but no how to solve my problem. 我知道为什么会这样,但是不知道如何解决我的问题。 Any ideas? 有任何想法吗?

@ManyToOne上的orphanRemoval = true解决了该问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM