我的代码如下所示:
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"
答案 0 :(得分:1)
错误是描述性的。执行代码的线程(get(...)
)没有绑定到它的休眠会话。也许您在新线程,线程池等中异步执行它?
如果是,您可以使用以下方法修复:
def get(Long id){
return Client.withSession {
return Client.findById(id);
}
}
而是在异步流开始的顶层执行此操作。