spring+hibernate多线程的事务配置

youshuideyu 2009-05-21 10:14:22
我在实现web service的异步调用,调用后将返回值写入数据库。开发环境是hibernate+spring,现在问题是新启的线程中无法写数据库。
applicationContext.xml中的关于事务的配置如下:
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="*" propagation="REQUIRED" rollback-for="Throwable" />
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut id="engineMethods"
expression="execution(* com.ibm.sapsoa.wsfacade.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="engineMethods" />
</aop:config>

多线程实现如下:
if (asyn) {
thread = new Thread(this);
thread.start();
}
public void run() {

loopCall(requestId,reqstatus);
}
在loopCall中进行循环调用webservice,并将返回值写入数据库的表中。

请教各位,给出一个解决方案。怎么进行配置才能实现在新线程中能进行写数据库操作。
...全文
506 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

25,980

社区成员

发帖
与我相关
我的任务
社区描述
高性能WEB开发
社区管理员
  • 高性能WEB开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧