我有一个Quest
包含许多Task
s 的实体:
@Entity
public class Quest {
@OneToMany(orphanRemoval=true,cascade=CascadeType.ALL)
@JoinColumn(name="quest_id")
@MapKey(name="taskName")
private Map<String, Task> tasks = Maps.createHash();
@ElementCollection
@OrderColumn
private Set<String> completedTasks;
@Entity
public class Task implements Serializable {
@ManyToOne(optional=false)
@JoinColumn(name="quest_id")
private Quest quest;
@Column(nullable=false,updatable=false,length=50)
private String taskName;
现在当我这样做时:
// store the task as completed
quest.getCompletedTasks().add(taskName); // set
// remove the task entity
quest.getTasks().remove(taskName); // map
Hibernate 尝试执行无意义的查询,但失败:
update Task set quest_id=null where quest_id='77149'
这似乎打破了任务与其所有任务之间的联系WHERE quest_id = ...
(DELETE
在任何情况下,它都不应该使任何东西无效,而应该Task
完全。
怎么了?