与石英一起使用Hibernate会话 [英] Using Hibernate session with quartz

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

问题描述

我有一个使用框架的Web应用程序,如Struts和Hibernate。目前,我正在使用Quartz开发此应用程序的调度程序。在编码时,我意识到使用Quartz的线程不可能使用Hibernate会话。

任何人都可以使用石英job类的hibernate会话解决方案吗?

解决方案

一种方法是使用 HibernateUtil class ,它在静态初始化器中构建 SessionFactory ,并通过 public static getter。你的Quartz作业可以创建 Session 作为 HibernateUtil.getSessionFactory()。getCurrentSession()并使用它。


I've a web application which uses framework like Struts and Hibernate. Currently I'm developing a scheduler for this application using Quartz. While coding I realized that the use of Hibernate session is not possible with the threads of Quartz.

Anybody have a solution for using hibernate sessions from quartz job class?

解决方案

One approach is to use a HibernateUtil class which builds the SessionFactory in a static initializer and makes it available via a public static getter. Your Quartz job can create a Session as HibernateUtil.getSessionFactory().getCurrentSession() and use it.

这篇关于与石英一起使用Hibernate会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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