开发者

Delete OneToOne relationship

开发者 https://www.devze.com 2023-04-07 16:59 出处:网络
We have the following mapping: @Entity public class A { private B b; @OneToOne public B getB() { return b; }

We have the following mapping:

@Entity
public class A {
    private B b;

    @OneToOne
    public B getB() {
        return b;
    }
}
开发者_运维问答

When we delete an object of class A it must not delete the referenced object B. At the moment we get an exception when we try to delete A because of the existing relationship to B. How is the correct mapping?


You should disable cascade delete

@OneToOne(cascade = {})

or you can try

@OneToOne(orphanRemoval=false)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号