如果我保存對象包含以下列表HibernateException的:發現同一個集合的兩種表示
@OneToMany(cascade=CascadeType.ALL, mappedBy="taskList")
@OrderColumn(name="position", nullable=false)
public List<Task> tasks = new ArrayList<Task>();
我得到的異常
org.hibernate.HibernateException: Found two representations of same collection
戲中的代碼!控制器看起來是這樣的:
TaskList taskList = taskList.findById(taskListId);
taskList.add(position, task);
taskList.save();
如果我這一塊它的工作原理之前插入taskList.refresh()
,但位置信息丟失(這會導致其他錯誤)。
這是一個Hibernate的bug還是我的代碼有問題?
你是對的。我忽略了這個註釋來縮短我的例子 - 可能是一個壞主意。 – deamon