Exception in thread “Thread-61” org.hibernate.HibernateException:No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
Grails框架中想要异步批量发送消息,这样可以缩短前端的响应时间。但是一个对象在保存时好像是必须开一个事务,否则会报上面的错误。这时候就需要在遍历的程序外面包一层。例子:User一个bean类
User.withTransaction{
users.each {
//自己的代码逻辑
it.save(flush: true)
}
}