Let's imagine the scenario: Entity Company
and Entity Address
has one-to-many bidirectional relationship. So Entity Address
will look like:
@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
}
I'm going to migrate these codes to Hibernate 4.3
where CascadeType.DELETE_ORPHAN
is deprecated. When I am trying to replace CascadeType.DELETE_ORPHAN
with orphanRemoval = true
, it seems that orphanRemoval = true
doesn't even exist in @ManyToOne
.
So my question is:
Does
AddressHbm
use@Cascade(CascadeType.DELETE_ORPHAN)
in@ManayToOne
incorrectly?If
@Cascade(CascadeType.DELETE_ORPHAN)
is misused here, is it valid to just remove it?