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();