HibernateException:找到同一个集合的两个表示 [英] HibernateException: Found two representations of same collection
问题描述
如果我保存包含以下列表的对象:
@OneToMany(cascade = CascadeType.ALL,mappedBy =taskList )
@OrderColumn(name =position,nullable = false)
public List< Task> tasks = new ArrayList< Task>();
我得到异常
org.hibernate.HibernateException:找到两个相同集合的表示
代码在玩!控制器如下所示:
TaskList taskList = taskList.findById(taskListId);
taskList.add(position,task);
taskList.save();
如果我插入 taskList.refresh()
在这个块之前它可以工作,但位置信息丢失了(这导致了其他错误)。
这是一个Hibernate错误还是我的代码有问题?解决方案问题是,Hibernate不支持 @OneToMany(mappedBy = ...)的组合。
和 @OrderColumn
。没有 mappedBy
Hibernate使用连接表,一切按预期工作。请参阅解释。
If I save an object containing the following list
@OneToMany(cascade=CascadeType.ALL, mappedBy="taskList")
@OrderColumn(name="position", nullable=false)
public List<Task> tasks = new ArrayList<Task>();
I get the exception
org.hibernate.HibernateException: Found two representations of same collection
The code in the Play! controller looks like this:
TaskList taskList = taskList.findById(taskListId);
taskList.add(position, task);
taskList.save();
If I insert taskList.refresh()
before this block it works, but the position information is lost (which leads to other errors).
Is this a Hibernate bug or is something wrong with my code?
The problem was, that Hibernate does not support the combination of @OneToMany(mappedBy=...)
and @OrderColumn
. Without mappedBy
Hibernate uses a join table and everything works as expected. See explanation.
这篇关于HibernateException:找到同一个集合的两个表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!