首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Session 错误1

2012-09-21 
Session 异常1异常一:org.hibernate.HibernateException:?No?Hibernate?Session?bound?to?thread,?and?con

Session 异常1

异常一:org.hibernate.HibernateException:?No?Hibernate?Session?bound?to?thread,?and?configuration?does?not?allow?creation?of?non-transactional?one?here ?

批量执行sql语句时调用:

HibernateTransactionManager transactionManager = (HibernateTransactionManager)ac.getBean("transactionManager");
Query query = transactionManager.getSessionFactory().openSession().
createSQLQuery("UPDATE tms_product p SET p.number_1 = 0");
query.executeUpdate();

说明:当没有事务启动的时候,getCurrentSession是无法创建Session的

当然,我的方法是不带事务的

为什么openSession可以,opensession是从sessionfactory得到一个新的session,所以可以使用,而getCurrentSession是从当前线程中得到事务开始时创建transaction的那个session

异常二:could not execute native bulk manipulation query

session写HQL:

session.CreateSqlQuery("DELETE VotableNode vn WHERE vn.votingSetBucketId = :bucketId").SetParameter("bucketId", buckedId).ExecuteUpdate();


热点排行