jBPM与Spring整合无法使用Hibernate的currentSession。

一切按部就班的配置但是只要加上
thread
jBPM就报错:
no jBPM DB schema: no JBPM4_EXECUTION table.

如果我去掉的thread,那么启动正常,但是由于我的项目里使用了getCurrentSession这个方法,如果去掉了这个配置,会导致运行异常,请问如何解决这个问题?

版本:
Spring 3
jBPM 4.4
Hiberante 3

web容器Tomcat。

谢谢

spring 整合hibernate管理事物后,session是绑定到事物的,而不是thread。此时hibernate.current_session_context_class应该是SpringSessionContext,而它又会在使用LocalSessionFactoryBean时自动的设置。所以就不需要你去设置current_session_context_class了!把这句配置去掉就OK了。

找到之前看过JBPM社区回答的原话了:
When you are using hibernate and let spring manage the transaction then the session should be bound to the transaction and not to thread. The hibernate.current_session_context_class property should be SpringSessionContext class. This is done automatically in LocalSessionFactoryBean. So you need not do anything extra.

Making a session bound to a thread does not make it transaction aware. You can manually start and stop as many transactions as you want in a thread. In an application server you should never use thread session context - that can be dangerous. You should use JTA. And with spring you should let spring set it.

http://community.jboss.org/message/523111

就应该使用getCurrentSession,这样session是不用你手动去开启关闭的!报了什么错?你把spring+hibernate配置文件贴出来!hibernate和spring整合后,不应该使用opensession的。如果是openSession的话是重新建立了一个新的session,和service层的事物不是同一个session了,也就不是当前thread中的 session了!贴错误,贴配置...

你现在需要补习一下spring和hibernate整合...

大概的瞅一眼就看出了很多问题:
1.transactionManager需要注入dataSouorce;

2.你的切点是定义在了dao层,如果按常规的controller,service,dao三层方式的话,业务逻辑应该都在service里面,所以,通常会把一个service当一块事物去处理。当然这个得按你实际的来,不是定死的。如果你没用service,而是把所有逻辑都写在了dao,那只能切在dao上了。

3.cn.com.fri.base.security.supports.UserDetailsServiceImpl.loadUserByUsername这个方法肯定没有在事物的控制范围,所以你用getCurrentSession是不行的。

4.[code="java"]
List list = new ArrayList();
Session session = this.getSessionFactory().getCurrentSession();
session.beginTransaction();
Query q = session.createQuery("from " + RolAut.class.getSimpleName()

  • " ent where ent.rolId in (:ids)"); q.setParameterList("ids", ids); list = q.list(); session.getTransaction().commit(); return list; [/code]

5.[code="xml"]

org.hibernate.transaction.JDBCTransactionFactory

[/code]
错误!(整合后没记错的话应该是org.springframework.orm.hibernate3.SpringTransactionFactory),我没写这个配置;

如果你已经使用spring+hibernate整合管理事物,那再需要你有.beginTransaction(); ,commit,closeSessioin等操作,这些由spring完成。

建议你去补习下spring和hibernate整合。