Questions tagged «many-to-one»

6
@ManyToOne JPA关联的CascadeType.ALL是什么意思
我认为我误解了@ManyToOne关系中级联的含义。 案子: public class User { @OneToMany(fetch = FetchType.EAGER) protected Set<Address> userAddresses; } public class Address { @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) protected User addressOwner; } 的含义是cascade = CascadeType.ALL什么?例如,如果我从数据库中删除某个地址,添加的事实会如何cascade = CascadeType.ALL影响我的数据(User我猜是)?

6
JPA:单向多对一和级联删除
假设我有如下所示的单向 @ManyToOne关系: @Entity public class Parent implements Serializable { @Id @GeneratedValue private long id; } @Entity public class Child implements Serializable { @Id @GeneratedValue private long id; @ManyToOne @JoinColumn private Parent parent; } 如果我有一个父P和一个返回给P的子C 1 ... C n,那么在JPA中是否有一种干净漂亮的方法来在删除P(即)时自动删除子C 1 ... C nentityManager.remove(P)? 我正在寻找的功能类似于ON DELETE CASCADESQL。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.