我的代码如下所示:
def get(Long id){
return Client.findById(id);
}
当调用此方法时,我收到这样的错误
2015-12-01 19:00:25,529 Failure execution thread for 1448974681594
org.springframework.dao.DataAccessResourceFailureException:
Could not obtain current Hibernate Session;
nested exception is org.hibernate.HibernateException:
No Session found for current thread
我正在使用 grails 2.5.1 和 Hibernate 插件“:hibernate4:4.3.8.1”
最佳答案
该错误是描述性的。执行您的代码 ( get(...)
) 的线程没有绑定(bind) hibernate session 。也许您在新线程、线程池等中异步执行它?
如果是,您可以使用以下方法修复它:
def get(Long id){
return Client.withSession {
return Client.findById(id);
}
}
而是在您的异步流程开始的顶层执行此操作。
关于hibernate - GORM 不工作。由 : org. hibernate.HibernateException 引起的错误:没有为当前线程找到 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34022416/