osworkflow2.8如何支持spring3.1+hibernate4?

osworkflow默认只支持hibernate3,而升级到hibernate4后,hibernate3.session是不适合hibernate4的,这要从源头变更才能解决问题。

原打算重写一下相关代码,看了看源代码,发现了更简单的解决办法。

其实解决很简单,对workflowstore自己实现一把就好了。:

SPRING配置:

<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
        <property name="transactionManager">
            <ref bean="transactionManager"/>
        </property>
        <property name="transactionAttributes">
        <props>
            <prop key="*">PROPAGATION_REQUIRED</prop>
        </props>
        </property>
    </bean>

    <bean id="workflowFactory" class=" com.opensymphony.workflow.spi.hibernate.SpringWorkflowFactory" init-method="init">
        <property name="resource">
            <value>workflows.xml</value>
        </property>
        <property name="reload">
            <value>false</value>
        </property>
    </bean>

    <bean id="workflowStore" class="com.xxx.core.workflow.spi.hibernate4.SpringHibernateWorkflowStore">

        <property name="sessionFactory">
            <ref bean="sessionFactory"/>
        </property>

        <property name="propertySetDelegate">
            <bean id="propertySetDelegate" class="com.opensymphony.workflow.util.PropertySetDelegateImpl"/>
        </property>

        <property name="cacheable"><value>true</value></property>
    </bean>

红色部分的实现,它将实现hibernate3里的AbstractHibernateWorkflowStore:


import com.opensymphony.workflow.StoreException;
import com.opensymphony.workflow.spi.hibernate3.AbstractHibernateWorkflowStore;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import java.sql.SQLException;

import java.util.Map;


/**
* xia
*/
public class SpringHibernateWorkflowStore extends AbstractHibernateWorkflowStore {
    private SessionFactory sessionFactory;

    public SpringHibernateWorkflowStore() {
        super();
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public void init(Map props) throws StoreException {
    }

    protected Object execute(final InternalCallback action) throws StoreException {

//更多的处理
        return action.doInHibernate(session);
    }
}

经测试,完全没有问题。

posted on 2012-06-29 11:15  夏雨的天空  阅读(410)  评论(0编辑  收藏  举报

导航