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

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

问题描述

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

  @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错误还是我的代码有问题? @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屋!

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