[英]Hibernate 3 On delete cascade
I have a many-to-one mapping on bookings. 我有一个多对一的预订映射。 A booking must belong to a room.
预订必须属于一个房间。 And a room can have several bookings.
一个房间可以有几个预订。
If a room is deleted, I would like all the bookings on that room to be deleted as well. 如果房间被删除,我希望删除该房间的所有预订。 How would i go about doing this using hibernate annotations?
我将如何使用hibernate注释来执行此操作?
@Entity
public class Booking implements Serializable{
@Id @GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private Date startDate;
private Date endDate;
private Date createdDate;
@ManyToOne
@JoinColumn (name = "roomId")
private Room room;
...
}
In your Room
entity you can have a 在您的
Room
实体中,您可以拥有
@OneToMany(cascade=CascadeType.REMOVE)
private List<Booking> bookings;
使用
@ManyToOne(cascade = CascadeType.REMOVE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.