Hibernate @Cascade(CascadeType.DELETE_ORPHAN)在应用于@ManyToOne时是否正确?

时间:2015-09-07 06:42:49

标签: java hibernate jpa all-delete-orphan

让我们想象一下场景:实体f1 = open('File 1') f2 = open('File 2') flag = True for file1_line, file2_line in zip(f1, f2): if file1_line[0] != file2_line[0]: flag = False break print(flag) 和实体Company具有一对多双向关系。因此,实体Address将如下所示:

Address

我要将这些代码迁移到@Entity @Table(name = "address") public class AddressHbm{ @Id @GeneratedValue(generator = "id-generator") @Column(name="address_id") private long id; @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE} ) @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN) @JoinColumn(name="company_id") private Company company = null; @Column(name="address_name") private String name; // other properties and methods } ,其中Hibernate 4.3已弃用。当我尝试将CascadeType.DELETE_ORPHAN替换为CascadeType.DELETE_ORPHAN时,似乎orphanRemoval = true中甚至不存在orphanRemoval = true

所以我的问题是:

  • @ManyToOne AddressHbm @Cascade(CascadeType.DELETE_ORPHAN)使用@ManayToOne会不正确?

  • 如果@Cascade(CascadeType.DELETE_ORPHAN)在这里被滥用,将其删除是否有效?

0 个答案:

没有答案