PDA

View Full Version : Spring jBPM Transactions Not Flushing


julian
Sep 10th, 2005, 03:52 PM
Hi all,

I have been working with the new jBPM code in the spring-modules CVS, but none of the calls are being persisted to the database. I have the following spring config, but it seems the JbpmSessionFactoryUtils class cannot get a handle on a Transaction via the TransactionSynchronizationManager. Whenever I instantiate a Hibernate Transaction directly, I have no problems. Also, I am able read data from the database, just not write. Any suggestions?

Thanks,
Julian


<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerD ataSource">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://localhost:5432/jbpm/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>

<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFac toryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="mappingLocations">
<value>classpath*:/org/jbpm/**/*.hbm.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="schemaUpdate" value="true"/>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransa ctionManager">
<property name="sessionFactory" ref="hibernateSessionFactory"/>
</bean>

<bean id="hibernateConfiguration" factory-bean="&amp;hibernateSessionFactory" factory-method="getConfiguration"/>

<bean id="jbpmSessionFactory" class="org.springframework.workflow.jbpm.LocalJbpmSession FactoryBean">
<property name="hibernateSessionFactory" ref="hibernateSessionFactory"/>
<property name="hibernateConfiguration" ref="hibernateConfiguration"/>
</bean>

<bean id="jbpmTemplate" class="org.springframework.workflow.jbpm.JbpmTemplate">
<property name="jbpmSessionFactory" ref="jbpmSessionFactory"/>
</bean>

robododge
Sep 16th, 2005, 12:49 AM
Julian,

I throughly tested the spring-jbpm module. Rob Harrop told me its still a work in progress, but everything including transaction management is working quite well for me. I've tested JbpmTemplate transaciton intermingled with my domain specific HibernateTemplate transactions. Commits and rollbacks for all participating in the transaction are applied as you would expect.

I'm using hypersonic right now, looks like you're using postgres.

I'd like to see your implementation class, here's one I'm using to test writing a ProcessDefinition then retrieving a ProcessInstance


public class SimpleProcessPAOImpl implements SimpleProcessPAO {

private JbpmTemplate jbpmTemplate;

public ProcessDefinition createProcessDef(String xmlFileResource, final String processName) {
final ProcessDefinition myDefinition = ProcessDefinition.parseXmlResource(xmlFileResource );
myDefinition.setName(processName);
ProcessDefinition processDef = (ProcessDefinition)jbpmTemplate.execute(new JbpmCallback(){

public Object doInJbpm(JbpmSession jbpmSession) throws Exception {
GraphSession gSession = jbpmSession.getGraphSession();
gSession.saveProcessDefinition(myDefinition);
return myDefinition;
}});

return processDef;
}

public void setJbpmSessionFactory(JbpmSessionFactory jbpmSessionFactory)
{
jbpmTemplate = new JbpmTemplate(jbpmSessionFactory);
}

public ProcessInstance findProcessInstance(Long processId) {
return jbpmTemplate.findProcessInstance(processId);
}

public ProcessInstance createNewProcessInstance(ProcessDefinition def) {
ProcessInstance resultInstance = new ProcessInstance(def);
long instanceId = jbpmTemplate.saveProcessInstance(resultInstance);
return resultInstance;

}



}


I'm calling this code inside of a transaction kicked of by the AbstractTransactionalDataSourceSpringContextTests class from spring-mock. In another case, to really see the transaction boundaries, I'm calling this code inside of a TransactionTemplate.execute().