【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 在没有数据库修改权限时,像创建视图可以使用 ...
随机推荐
- 服务器表导入到本地数据库SQL语句
这是开启权限 exec sp_configure 'show advanced options',1 reconfigure exec sp_configure 'Ad Hoc Distributed ...
- BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草( dp )
-------------------------------------------------------------------- #include<cstdio> #include ...
- 自己动手写 ASP.NET MVC 分页 part1
学习编程也有一年半载了,从来没有自己动手写过东西,都是利用搜索软件找代码,最近偶发感慨,难道真的继续做码农??? 突发奇想是不是该自己动手写点东西,可是算法.逻辑思维都太弱了,只能copy网上的代码, ...
- php如何开启GD库
GD库是干什么用的呢!它是php处理图形的扩展库,GD库提供了一系列用来处理图片的API,使用GD库可以处理图片,或者生成图片.GD库在php中默认是没有开启的,如果想让它支持图片处理功能,那么就要手 ...
- [LeetCode]题解(python):007-Reverse Integer
题目来源: https://leetcode.com/problems/reverse-integer/ 题意分析: 这道题目很简单,就是将一个数反转,123变321,-123变321. 题目思路: ...
- 第一个VC++ win32程序 绘制简单图形
创建一个VC++ win32 打开VS 新工程类型中选择Win32----Win32 Project 自己取个名字(假如叫做My1stWin) 一路next 系统会自动生成好最基本的代码 然后我们 ...
- S70卡
产品名称:Mifare 4K(S70)卡 芯片类型:Philips Mifare 1 S70(MOA2) 存储容量:32Kbit,32个分区,每分区两组密码 工作频率:13.56 MHz 通讯 ...
- HDU 3307 Description has only two Sentences
数学实在是差到不行了…… #include <cstdio> #include <cstring> #include <algorithm> #include &l ...
- Android测试TestSuite的执行方法
public class StartTest extends InstrumentationTestRunner { public TestSuite getAllTests() { ...
- Break the Chocolate(规律)
Break the Chocolate Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...