首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

spring框架中平添HibernateInterceptor使得quartz可以调用Hibernate Session

2012-10-11 
spring框架中添加HibernateInterceptor使得quartz可以调用Hibernate Session1.spring2.hibernate3.quartz-

spring框架中添加HibernateInterceptor使得quartz可以调用Hibernate Session
1.spring

2.hibernate

3.quartz--定时调度工具,spring已经做了封装,也可以单独使用。

4.OpenSessionInViewFilter--web框架下的一个filter,能够让web request使用单一的hibernate session。

有的j2ee项目在web.xml文件中添加了OpenSessionInViewFilter,其目的是给web request提供单一的hibernate session,但是它也只能给web request提供hibernate session。也就是说,如果有某一个hibernate请求不是经由web request发起的,而是由quartz这样的定时任务发起的,那么quartz怎么样才能得到hibernate session呢?

解决办法就是使用HibernateInterceptor。当quartz发起hibernate session请求时,HibernateInterceptor会提供一个hibernate session给它。

配置文件如下:



xml 代码


<!-- Declaration of HibernateInterceptor -->  
    <bean id="hibernateInterceptor" abstract="true"  
        ref="transactionManager"/>  
        <property name="transactionAttributes">  
            <props>  
                <prop key="save*">PROPAGATION_REQUIRED</prop>  
                <prop key="remove*">PROPAGATION_REQUIRED</prop>  
                <prop key="update*">PROPAGATION_REQUIRED</prop>                   
                <prop key="create*">PROPAGATION_REQUIRED</prop>      
                <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>  
            </props>  
        </property>  
        <property name="preInterceptors">  
            <list>  
             <ref bean="hibernateInterceptor"/>  
            </list>  
        </property>                           
    </bean>  
    <!-- Sample Manager that encapsulates business logic -->  
    <bean id="userManager" parent="txProxyTemplate">  
        <property name="target">  
            <bean autowire="byName"/>  
        </property>  
    </bean>  



其中,<!-- Declaration of HibernateInterceptor -->部分定义了HibernateInterceptor;

<!-- Manager template  -->部分定义了模板,并且加入了HibernateInterceptor;

<!-- Sample Manager that encapsulates business logic -->部分定义业务逻辑中的bean,记住,一定让他使用模板。


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/WiseDragon/archive/2008/11/19/3325809.aspx

热点排行