Hibernate插入连接表
我得到了几个实体。其中两个建立了多对多关系。当我对这些实体执行更大的操作时,它会失败并出现以下异常:
org.hibernate.exception.ConstraintViolationException: could not insert collection rows:
我在 @Transactional 上下文中执行操作。我不会对我的 daos 进行任何明确的刷新。刷新由查询触发。队列中有 15 个元素(全部具有相同的结构)。其中一个总是失败(但它总是不同的(我检查过)并且总是在不同的位置)。
有人对我可能做错的事情有提示吗?
我的映射:
@ManyToMany(targetEntity = CategoryImpl.class)
protected Set<Category> categories = new HashSet<Category>();
I got several entities. Two of them got a many-to-many relation. When I do a bigger operation on these entities it fails with this exception:
org.hibernate.exception.ConstraintViolationException: could not insert collection rows:
I execute the operation i a @Transactional context. I don't do any explicit flushing i my daos. The flush is triggered by a query. In the queue are 15 elements (all of the same structure). one of them always fails (but it's always a different one (I checked) and always at a different position).
Does anybody have a hint for me for what I might do wrong?
My Mapping:
@ManyToMany(targetEntity = CategoryImpl.class)
protected Set<Category> categories = new HashSet<Category>();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以目前的详细程度很难说。该关联是双向的吗?您是否定义了一个拥有方(另一方有
mappedBy
)?您能否启用日志记录以查看执行的查询并确定导致问题的查询。Hard to say with the current level of detail. Is the association bidirectional? Do you have one owning side (with a
mappedBy
on the other side) defined? Can you enable logging to see the executed queries and identify the one which is causing the problem.