【发布时间】:2015-06-29 14:37:50
【问题描述】:
我正在尝试通过从实体中删除嵌入来删除嵌入中的列表。这不起作用..列表中的所有实体仍在数据库中。
代码:
一切开始的方法:
//attached entity
Ship ship = findShip();
ship.removeItinerary();
船:
@Entity
@Table(name = "SHIP")
public class Ship extends Domain {
@Embedded
private Itinerary itinerary;
public void removeItinerary() {
this.itinerary = null;
}
}
行程:
@Embeddable
public class Itinerary implements Serializable {
//tried orphanRemoval and cascade but without luck
//(since I'm not removing the Ship it's actually logic that it's not working..)
@OneToMany
@JoinColumn(name = "SHIP_ID", referencedColumnName = "ID")
private List<Stop> stops = new ArrayList<>();
}
JPA 2.0
【问题讨论】:
-
我终于弄清楚我做错了什么。我总是在船上保存一个新的 Itinerary()。错误实际上不在此代码中。对于其他人:orphanRemoval 和 cascade.update 的组合可以解决问题。