HibernateException:找到相同集合的两个表示 [英] HibernateException: Found two representations of same collection

查看:20
本文介绍了HibernateException:找到相同集合的两个表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我保存一个包含以下列表的对象

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>();

我得到了异常

org.hibernate.HibernateException: Found two representations of same collection

Play 中的代码!控制器看起来像这样:

The code in the Play! controller looks like this:

TaskList taskList = taskList.findById(taskListId);
taskList.add(position, task);
taskList.save();

如果我在这个块之前插入 taskList.refresh() 它可以工作,但是位置信息丢失了(这会导致其他错误).

If I insert taskList.refresh() before this block it works, but the position information is lost (which leads to other errors).

这是 Hibernate 错误还是我的代码有问题?

Is this a Hibernate bug or is something wrong with my code?

推荐答案

问题是,Hibernate 不支持 @OneToMany(mappedBy=...)@ 的组合订单列.如果没有 mappedBy,Hibernate 使用连接表,一切都按预期工作.请参阅说明.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆