配置OSWorkFlow通过Hibernate持久化

1.修改WEB-INF\classes\目录下的osworkflow.xml,改为

     <persistence class="com.opensymphony.workflow.spi.hibernate.HibernateWorkflowStore">
     </persistence>

2.将下面的Hibernate.cfg.xml加到WEB-INF\classes\下面,这里使用mysql数据库。

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>
 <!-- properties -->
 <property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
 <property name="connection.url">jdbc:mysql://redhat:3306/osworkflow</property>
 <property name="connection.username">redhat</property>
 <property name="connection.password">redhat</property>

 <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
 <property name="show_sql">true</property>
 <property name="use_outer_join">true</property>

 <property name="connection.pool_size">10</property>
 <property name="statement_cache.size">25</property>

 <property name="hibernate.hbm2ddl.auto">update</property>

 <mapping resource="com/opensymphony/workflow/spi/hibernate/HibernateCurrentStep.hbm.xml"></mapping>
 <mapping resource="com/opensymphony/workflow/spi/hibernate/HibernateHistoryStep.hbm.xml"></mapping>
 <mapping resource="com/opensymphony/workflow/spi/hibernate/HibernateWorkflowEntry.hbm.xml"></mapping>
 <mapping resource="com/opensymphony/module/propertyset/hibernate/PropertySetItemImpl.hbm.xml"></mapping>

</session-factory>
</hibernate-configuration>

3.把hibernate的jar及hibernate所有要到的jar,到WEB-INF\lib\
4.OSWorkflow要求客户端提供SessionFactory,自主控制session和transaction。在容器里可以直接生成SessionFactory然后注入到workflow中。这里只是演示,所以直接修改.jsp文件,生成SessionFactory,传入workflow中。


    Workflow wf = new BasicWorkflow((String) session.getAttribute("username"));

// osworkflow和hibernate竟然都是通过Configuration类来进行配置的,没办法,谁让大家都需要进行配置而就那么几个单词呢
 com.opensymphony.workflow.config.Configuration conf = new DefaultConfiguration();

 SessionFactory sessionFactory = new net.sf.hibernate.cfg.Configuration().configure().buildSessionFactory();
 conf.getPersistenceArgs().put("sessionFactory", sessionFactory);
 wf.setConfiguration(conf);

5.OK搞定。

 

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1552535

你可能感兴趣的:(xml,mysql,Hibernate,workflow,redhat)