线程中的Hibernate会话 [英] Hibernate session in threads

查看:129
本文介绍了线程中的Hibernate会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务有一些问题,作为源自外部库的某些事件的侦听器,该库创建一个读取通信端口的线程并将数据发回给我的侦听器(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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆