让我们想象一下场景:实体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)
在这里被滥用,将其删除是否有效?