【Hibernate】Illegal attempt to associate a collection with two open sessions
今天在用Hibernate对对象进行修改操作的时候报了这个错。
之前一直没什么错误,但是今天修改了一下表结构,增加了一个OneToMany的映射。
所以在我获取对象,重新set一个变量之后就报了这个错误了。
Illegal attempt to associate a collection with two open sessions; nested exception is org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
网上查了一下,说是不同session直接对象的操作造成的,原因还有待查明。
目前暂时采用了下面的方法
在修改完对象值之后,给对象的OneToMany的List设置null值就可以了。
Dao<Resources> resourcesDao=TitanContext.getDaoProxy(Resources.class);
Resources resource = resourcesDao.find(id);
resource.setClickCount(resource.getClickCount()+1);
resource.setResourcePeriod(null);
resourcesDao.update(resource);
先做下备注。
【Hibernate】Illegal attempt to associate a collection with two open sessions的更多相关文章
- 同时操作两个数据库:报错Illegal attempt to associate a collection with two open sessions
今天我在一个操作两个数据库的SSH里 同时插入1条数据 报错 Illegal attempt to associate a collection with two open sessions 在这里有 ...
- 异常描述:hibernate懒加载中,用OpenSessionInViewFilter解决之后,同时对一个collection创建两个session访问导致异常(Illegal attempt to associate a collection with two open sessions)
在保存的时候如果使用以下方法就会报错 解决:使用merge()方法就可以解决异常... merge()方法的解释: 传入的参数在数据库中不存在的时候会添加一条数据,根据主键判断已存在的时候会更新这条数 ...
- 解决org.hibernate.QueryException illegal attempt to dereference collection 异常错误
今天做项目的时候,有两个实体:款式.品牌两者关系是多对多的关联关系,实现的功能是:通过选择款式,显示出该款式的所有品牌.HQL语句如下: 运行时出现这个异常错误:org.hibernate.Query ...
- 【Hibernate】Hibernate的多表查询
在<[Hibernate]Hibernate的聚类查询.分组查询.排序与时间之差>(点击打开链接)一文中已经讲述过怎样利用HQL语句代替SQL语句.进行聚类查询.分组查询.排序与时间之差的 ...
- 【hibernate】映射继承关系
[hibernate]映射继承关系 转载:https://www.cnblogs.com/yangchongxing/p/10405151.html ========================= ...
- 【hibernate】自定义转换器
[hibernate]自定义转换器 转载:https://www.cnblogs.com/yangchongxing/p/10398255.html 1.转换基本属性 package cn.ycx.s ...
- 【hibernate】存储图片
[hibernate]存储图片 转载: package cn.ycx.study.hibernate.entity; import javax.persistence.Entity; import j ...
- 【hibernate】映射可嵌入式组件
[hibernate]映射可嵌入式组件 转载:https://www.cnblogs.com/yangchongxing/p/10376452.html 可嵌入 Address 类,没有对应的数据表 ...
- 【hibernate】应用程序级别的视图
[hibernate]应用程序级别的视图 转载:https://www.cnblogs.com/yangchongxing/p/10361281.html 在没有数据库修改权限时,像创建视图可以使用 ...
随机推荐
- 我用过的Linux命令--关闭防火墙
关闭防火墙: 防火墙的弄能是限制某一些端口的使用,可以通过linux命令关系它,相应的指令: 查看防火墙信息: #service iptables status 就能看到防火墙的状态: 关闭防火墙: ...
- [LeetCode]题解(python):106-Construct Binary Tree from Inorder and Postorder Traversal
题目来源: https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/ 题意分析 ...
- Output in PowerShell
Reference article: https://rkeithhill.wordpress.com/2007/09/16/effective-powershell-item-7-understan ...
- 【转】vs2008中leptonica-1.68安装配置
tesseract ocr挺不好配置的,找到一篇不错的文章,分享如下:http://hi.baidu.com/ever8936/blog/item/6998e1196b1d0161dab4bd8f.h ...
- NET Core Docker部署
NET Core Docker部署 前言 在前面文章中,介绍了 ASP.NET Core在 macOS,Linux 上基于Nginx和Jexus的发布和部署,本篇文章主要是如何在Docker容器中运行 ...
- Move WriteBuffer ReadBuffer String
在实际编程中,经常会用到Buffer,当string作为Buffer传值时需要注意的是 1, string的值的起始索引是1,千万记住! 2, 有时候需要先告诉系统去开辟出内存空间,用SetLengt ...
- 部署vc2008开发的程序(vcredist_x86是其中一个办法)
如果你编译了一个VC2008的默认的CRT/MFC的应用程序,如果目标部署电脑上没有安装相应的VC2008的动态库,当运行你的程序的时 个,会出现如下错误信息. 这是因为程序使用了基于VC2008 ...
- Qt实战之开发CSDN下载助手 (3)(结束篇)
再次申明下,开发这款助手,主要是用来学习交流,并不是用来开发什么刷积分的软件. 好了,言归正传,这次,主要的分析下CSDN的下载,评论,验证码获取机制等等. 好,回到第二篇,当我们成功登陆时,CSDN ...
- elk 分布式数据同步
zjtest7-redis:/elk/elasticsearch/data/es_cluster/nodes/0/indices/library# strings ./1/index/_3.cfs | ...
- 使用 IIS Manager 对 Windows Azure 网站进行远程管理
最近,我们为客户新增了使用 Windows自带的 IIS管理控制台管理 Azure网站的功能.IIS Manager支持 HTTP over SSL,提供到您的 Windows Azure 网站 ...