线程中的Hibernate会话 [英] Hibernate session in threads
问题描述
我的服务有一些问题,作为源自外部库的某些事件的侦听器,该库创建一个读取通信端口的线程并将数据发回给我的侦听器(grails服务)案例。
问题是,当读取线程调用方法时,我无法更新数据库,因为grails会将hibernate会话绑定到线程。
有任何机会获得该线程的休眠会话?
有一个配置参数传播或注入会话到线程??
我看过后台线程插件,但它似乎只有在线程由grails创建。
我认为你没有获得会话,因为你的服务没有被调用为标准的http请求。
Grails提供了一些简便的方法,比如
withSession
withNewSession
withTransaction
可能适合帐单
Im having some problem with a service that acts as a listener of some events that are originated from an external library, that library creates a thread for reading comm port and send back the data to my listener (the grails service) on certain cases. The problem is that i cannot update the database when methods are called from the reading thread becose grails bound the hibernate session to threads.
There is any chance to get the hibernate session for that thread?? There is a configuration parameter to propagate or inject the session to threads??
i have seen the background thread plugin but it seems that is only useful if the thread is created by grails.
I think you are not getting a session because your service is not being invoked as part of a standard http request.
Grails has some convenience methods like
withSession
withNewSession
withTransaction
that might fit the bill
这篇关于线程中的Hibernate会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!