Hibernate 拦截器
来源:互联网 发布:淘宝网手机版支付宝 编辑:程序博客网 时间:2024/05/19 03:46
也就是说,只有只能提供给web request的hibernate连接。
如果不是web request需要hibernate连接,怎么办?还是有办法的,使用hibernateInterceptor。
做法是:
1.声明一个hibernateInterceptor,其中的sessionFacory是你的hibernate sessionvFactory的bean名
<!-- Declaration of HibernateInterceptor -->
<bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
2.定义一个模板,声明在什么情况下使用此模板,并且指定和哪些hibernateInterceptor合成
<!-- Manager template -->
<bean id="txProxyTemplate" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" 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>
3. 声明一个自定义bean的时候适用模板,这样即可以在web request的时候适用当前hibernate session, 使用其他方式调用,
比如quartz调用的时候,也可以绑定hibernate session。
<!-- Sample Manager that encapsulates business logic -->
<bean id="userManager" parent="txProxyTemplate">
<property name="target">
<bean class="com.acme.service.impl.UserManagerImpl"/>
</property>
</bean>
- Hibernate拦截器
- Hibernate 拦截器
- Hibernate拦截器
- hibernate拦截器demo
- Hibernate 拦截器实例
- Hibernate拦截器
- Hibernate拦截器
- Hibernate拦截器
- Hibernate拦截器和监听器
- Hibernate拦截器和监听器
- Hibernate拦截器(Interceptor)【转】
- Hibernate拦截器与监听器
- hibernate拦截器与事件
- Hibernate拦截器和监听器
- Hibernate 拦截器Interceptor使用
- hibernate拦截器onFlushDirty无效
- hibernate拦截器与事件
- hibernate-jpa拦截器使用
- ALSA SOC架构关键点
- goldengate 同步无主键表
- IPv6地址格式及地址配置方式
- jexcel 导出excel文件的demo
- 第十四周 任务二
- Hibernate 拦截器
- 文件目录操作命令
- javascript控制页面元素的显示与隐藏
- 图案解锁源码,
- acm 关于高精度算法的教训
- SQL语句效率
- snd_kcontrol探究
- 有感于腾讯的GDOC
- html 空格问题