zoukankan      html  css  js  c++  java
  • 【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);

    先做下备注。

  • 相关阅读:
    CentOS7 安装 Mysql5.6.40
    CentOS7 安装 Python3.6.5
    CentOS7 添加新用户并授权 root 权限
    02 常用数据结构
    01 常见算法
    初识 Docker
    glob & fnmatch -- 使用Unix style通配符
    Pillow6 起步
    leetcode70. 爬楼梯 🌟
    leetcode69. x 的平方根 🌟
  • 原文地址:https://www.cnblogs.com/zengweiming/p/3977810.html
Copyright © 2011-2022 走看看