PDA

View Full Version : jbpm getting started


craig
Mar 23rd, 2006, 03:27 PM
I have been able to download and build the jbpm 31 integration.

I have looked but cannot find any examples of setting up an engine which I can use withing my application. Does anyone have a 'Hello World' example which includes the applicationContext.xml ?

Thanks,
Craig

Costin Leau
Mar 24th, 2006, 01:42 AM
There isn't any sample for jbpm at the moment. I'll try to make one or migrate an existing one from plain jbpm to spring jbpm support. You can take a look at the tests which contain application context definitions. Can you also please, raise an issue on jira under spring modules? thanks.

craig
Mar 27th, 2006, 06:30 PM
thanks for the hints Costin.

i raised the jira issue as asked.

I have looked at the tests, but cannot figure out how to set up the factorybean.

I would like to pass in a mysql connection for the hibernate. I know how to set up transaction managers, and a mysql connection...but, how would I configure it to use a specific database, with the default hbm files?

Here is what I have in my application context...it fails in the afterPropertiesSet...I am not sure which of the two configuration methods to use (JbpmConfiguration, or ObjectFactory)

any help would be much appreciated.

craig


<bean id="jbpmSessionFactoryBean" class="org.springmodules.workflow.jbpm31.LocalJbpmConfigu rationFactoryBean">
<!-- <property name="hibernateSessionFactory" ref="mySessionFactory"/> -->
</bean>

<bean id="processDefinition" class="org.springmodules.workflow.jbpm31.definition.Proce ssDefinitionFactoryBean">
<property name="jbpmSessionFactory" ref="jbpmSessionFactoryBean"/>
<property name="definitionLocation" value="classpath:/demo-process.xml"/>
</bean>

<bean id="jbpmDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost/jbpm</value>
</property>
<property name="username">
<value>${jdbc.user}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
</bean>

Costin Leau
Mar 27th, 2006, 06:49 PM
What's the message? Have you looked at the generated javadocs?

craig
Mar 27th, 2006, 07:28 PM
Yup, I have read it all.

I also tried this:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost/jbpm"/>
<property name="username" value="aaaaa"/>
<property name="password" value="xxxxxx"/>
</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.MySQLDialect</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="hibernateSessionFactory" factory-method="getConfiguration"/>

<bean id="jbpmSessionFactory" class="org.springmodules.workflow.jbpm31.LocalJbpmConfigu rationFactoryBean">
<property name="hibernateSessionFactory" ref="hibernateSessionFactory"/>
<property name="hibernateConfiguration" ref="hibernateConfiguration"/>
</bean>

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

</beans>


I get this error:
ERROR web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'hibernateConfiguration' defined in ServletContext resource [/WEB-INF/classes/jpbmContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionSt oreException: No factory method: factory bean=hibernateSessionFactory; factory method=getConfiguration
org.springframework.beans.factory.BeanDefinitionSt oreException: No factory method: factory bean=hibernateSessionFactory; factory method=getConfiguration
at org.springframework.beans.factory.support.Construc torResolver.instantiateUsingFactoryMethod(Construc torResolver.java:271)

craig
Mar 27th, 2006, 07:54 PM
getting further...i had missed the &. However, if I call getConfiguration on the hibernate session factory the return type is Configuration....the LocalJbpmConfigurationFactoryBean has a method setConfiguration, but is expecting resource.

I don't see what I should be setting, setObjectFactory, or setConfiguration.

craig
Mar 27th, 2006, 08:05 PM
Ok, now I am getting there. I hadn't seen the applicationContext which was in the testing folder, i had looked in the source package.

That has all the information I need to set it up properly.

Costin Leau
Mar 28th, 2006, 03:03 AM
I hadn't seen the applicationContext which was in the testing folder
That's what I meant by tests. jbpm 3.1 support is different from jbpm 3.0 since jbpm itself has been modified quite a lot. Even though there are some similarities the classes and underlying architecture has changed - one aspect would be that you don't need to pass in a Hibernate configuration.

tobysaville
May 19th, 2006, 08:39 AM
Ok, now I am getting there. I hadn't seen the applicationContext which was in the testing folder, i had looked in the source package.

That has all the information I need to set it up properly.
where is the testing folder your refering to here?

Costin Leau
May 19th, 2006, 03:17 PM
inside the springmodules 0.3 distribution and the latest version on the spring modules cvs.

wrschneider99
Jun 3rd, 2006, 02:50 PM
Here's how I am incorporating jBPM 3.1 into an existing Hibernate3/Spring app. My goal is to have a single SessionFactory for jBPM and the rest of my app, so everything participates in the same Spring declarative transactions.

- add jbpm-3.1.1.jar to WEB-INF/lib.
- in applicationContext.xml, I created a bean for JbpmConfiguration

<bean id="jbpmConfig"
class="org.springmodules.workflow.jbpm31.LocalJbpmConfigu rationFactoryBean">
<!-- pass in existing sessionFactory -->
<property name="sessionFactory" ref="sessionFactory"/>
<property name="configuration" value="WEB-INF/jbpm.cfg.xml"/>
<property name="processDefinitions">
<list>
<ref local="process1"/>
</list>
</property>
</bean>

<bean id="process1" class="org.springmodules.workflow.jbpm31.definition.Proce ssDefinitionFactoryBean">
<property name="definitionLocation" value="WEB-INF/process1.xml"/>
</bean>

- sessionFactory/hibernate configuration has to incorporate all of the jBPM org.jbpm.....hbm.xml mappings *and*your own.

- jbpm.cfg.xml copy-pasted from jBPM docs, but I took out reference to hibernate.cfg.xml since the SessionFactory is being provided via Spring.

- process defs (process1.xml etc.) are normal.

- you have to create the DB tables yourself somehow.

Only problem: it seems like this is causing a new version of each process to be redeployed to the jbpm_processdefinition table every time the app is restarted. This seems a little odd, and may make the Spring-based process deployment less useful.

Costin Leau
Jun 3rd, 2006, 02:55 PM
Only problem: it seems like this is causing a new version of each process to be redeployed to the jbpm_processdefinition table every time the app is restarted. This seems a little odd, and may make the Spring-based process deployment less useful.

Do you have any idea what causes this redeployment? Is it caused by Spring integration? Can you please raise an issue on jira so I can take a look at it and fix it on our next Spring Modules release?
Thanks.

wrschneider99
Jun 3rd, 2006, 03:20 PM
Do you have any idea what causes this redeployment? Is it caused by Spring integration? Can you please raise an issue on jira so I can take a look at it and fix it on our next Spring Modules release?
Thanks.

Wow, thanks for the quick reply. now that's service!

Honestly, I have no idea why this is happening. I'm new to jBPM, and right now focused on just getting the basic configuration and db connection/tx mgmt right.

I'm not sure what ProcessDefinitionFactoryBean does. Here's my process1.xml in case there's something unusual here:

<process-definition name="process1">
<start-state>
<transition to='s' />
</start-state>
<state name='s'>
<transition to='end'/>
</state>
<end-state name='end' />
</process-definition>

Costin Leau
Jun 3rd, 2006, 04:50 PM
Your process seems to be just fine. What jbpm version are you using? Lately I've been a bit swamped in work and I didn't have much time to do the jbpm documentation but it's high on my Spring Modules priority list (you can actually vote the jira issue).
I'll try to reproduce your problem though from my tests I haven't had such a problem.

wrschneider99
Jun 3rd, 2006, 08:26 PM
Your process seems to be just fine. What jbpm version are you using? Lately I've been a bit swamped in work and I didn't have much time to do the jbpm documentation but it's high on my Spring Modules priority list (you can actually vote the jira issue).
I'll try to reproduce your problem though from my tests I haven't had such a problem.

I'm using jbpm 3.1.1.

Costin Leau
Jun 4th, 2006, 07:03 AM
I have tested only with jbpm 3.1.0. I'll let you know if I find anything.

Costin Leau
Jun 4th, 2006, 07:06 AM
FYI, I've created an issue on JIRA: http://opensource.atlassian.com/projects/spring/browse/MOD-136

tobysaville
Jun 4th, 2006, 11:02 AM
sorry if this is off topic now, but im following up on my post refering to the test folder earlier.

I have had a look in the zip distribution & at the online cvs repository, but i cant find the testing folder with the example applicationContext.xml file.

specifically, i am having trouble defining the hibernateConfiguration property of my org.springmodules.workflow.jbpm30.LocalJbpmSession FactoryBean bean (im using jbpm 3.0.2). I already have a org.springframework.orm.hibernate3.LocalSessionFac toryBean defined in my applicationContext.xml and i would like to use the configuration from this session factory. can you point me in the right direction regarding this?

My bean def so far:


<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFac toryBean">
<property name="mappingResources">
<list>
<value>...</value>
</list>
</property>
<property name="hibernateProperties">
<props>...</props>
</property>
<property name="dataSource">
<ref bean="..."/>
</property>
</bean>

<bean id="jbpmSessionFactoryBean" class="org.springmodules.workflow.jbpm30.LocalJbpmSession FactoryBean">
<property name="hibernateSessionFactory" ref="hibernateSessionFactory"/>
</bean>


Thanks for any assistance forthcoming

- tobes

Costin Leau
Jun 5th, 2006, 09:38 AM
See this link from CVS: https://springmodules.dev.java.net/source/browse/springmodules/projects/jbpm30/src/test/org/springmodules/workflow/jbpm30/
I'll put up some documentation so it will be part of the next release. Clearly there is a need for it.

scott_mathieson
Jun 5th, 2006, 11:32 AM
Hi,

I have also seen the problem with new versions of processes being created, this is due to the fact that the deployProcessDefinition method of GraphSession in JBPM 3.1.1 ensures that a new process definition with an updated version is saved if the process name already exists.

I think I just need to come up with a method of flagging whether or not to deploy process definitions in the spring config file as currently my process definitions are specified in the Spring config file and as such are continuially re-deployed every time the server starts.

Any useful suggestions would be most welcome :)

Regards

Scott

tobysaville
Jun 5th, 2006, 01:07 PM
See this link from CVS: https://springmodules.dev.java.net/source/browse/springmodules/projects/jbpm30/src/test/org/springmodules/workflow/jbpm30/
I'll put up some documentation so it will be part of the next release. Clearly there is a need for it.

sweet as mustard, cheers.

Costin Leau
Jun 6th, 2006, 02:30 AM
Have you tried the jbpm forums? I'm curios myself why a new updated version is saved on redeploy. I guess one way is to extend the method (if possible) and override the behavior - a bit risky but will get the job done.

scott_mathieson
Jun 6th, 2006, 06:17 AM
Hi,

I have managed to get round this issue, but I think my solution is a bit hacky:

I extended the LocalJbpmConfigurationFactoryBean as shown below to have an additional property used to determine whether it should re-deploy a process definition if one of the same name already exists.


import java.io.InputStream;
import java.util.Arrays;

import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.configuration.ObjectFactory;
import org.jbpm.configuration.ObjectFactoryParser;
import org.jbpm.graph.def.ProcessDefinition;
import org.springframework.core.io.Resource;
import org.springmodules.workflow.jbpm31.LocalJbpmConfigu rationFactoryBean;

/**
*
* @author Scott
*/
public class CustomLocalJbpmConfigFactoryBean extends LocalJbpmConfigurationFactoryBean {

private boolean redeployProcesses = false;
private static Logger logger = Logger.getLogger(CustomLocalJbpmConfigFactoryBean. class);

private JbpmConfiguration jbpmConfiguration;

/**
* @see org.springframework.beans.factory.FactoryBean#getO bject()
*/
public Object getObject() throws Exception {
return jbpmConfiguration;
}

/**
* @see org.springframework.beans.factory.FactoryBean#getO bjectType()
*/
public Class getObjectType() {
return JbpmConfiguration.class;
}

public boolean isRedeployProcesses() {
return redeployProcesses;
}

public void setRedeployProcesses(boolean redeploy) {
redeployProcesses = redeploy;
}
/**
* @see org.springframework.beans.factory.InitializingBean #afterPropertiesSet()
*/
public void afterPropertiesSet() throws Exception {
Resource configuration = this.getConfiguration();
ObjectFactory objectFactory = null;
SessionFactory sessionFactory = this.getSessionFactory();
ProcessDefinition[] processDefinitions = this.getProcessDefinitions();
String contextName = this.getContextName();
boolean createSchema = this.isCreateSchema();

if (configuration == null && objectFactory == null)
throw new IllegalArgumentException("configuration or objectFactory property need to be not null");

ObjectFactory jbpmObjectFactory;

// 1. create the configuration from the file
if (configuration != null) {
logger.info("creating JbpmConfiguration from resource " + configuration.getDescription());
InputStream stream = configuration.getInputStream();
jbpmObjectFactory = ObjectFactoryParser.parseInputStream(stream);
stream.close();
}
else
jbpmObjectFactory = objectFactory;

jbpmConfiguration = new JbpmConfiguration(jbpmObjectFactory);

// 2. inject the HB session factory if it is the case
if (sessionFactory != null) {
logger.info("using given Hibernate session factory");
JbpmContext context = jbpmConfiguration.createJbpmContext(contextName);
try {
context.setSessionFactory(sessionFactory);
}
finally {
context.close();
}
}

// 3. execute persistence operations
if (createSchema) {
logger.info("creating schema");
jbpmConfiguration.createSchema(contextName);
}

if (processDefinitions != null && processDefinitions.length > 0) {
//TODO: replace with another faster utility
String toString = Arrays.asList(processDefinitions).toString();
logger.info("deploying process definitions:" + toString);
JbpmContext context = jbpmConfiguration.createJbpmContext(contextName);
try {
for (int i = 0; i < processDefinitions.length; i++) {
// Only deploy process that don't already exist or if the redeploy flag is set.
String name = processDefinitions[i].getName();
ProcessDefinition def = context.getGraphSession().findLatestProcessDefinit ion(name);
if (def == null || redeployProcesses) {
context.deployProcessDefinition(processDefinitions[i]);
}
else {
logger.info("Skipping definition : " + def.getName());

// Replace the process definition entry with the one loaded by the context.
processDefinitions[i] = def;
}
}
}
finally {
context.close();
}
}
}

}


I then had issues with persisting new Process instances as the JbmpTemplate was using the ProcessDefinition retrieved from the ProcessDefinitionFactoryBean so what I ended up doing was setting the ProcessDefinition property of the template manually by looking up the process definition latest version using the name before using the template.

Can anyone come up with a more elegant solution to this?

Regards,

Scott

PS: Is this the correct thread for this, sorry if I'm posting in the wrong place.

Costin Leau
Jun 6th, 2006, 07:04 AM
I don't think there is any easy way out. The code is also dependent on jbpm 3.1.1 (the issue from what I understand doesn't occur on 3.1.0).
Have you discussed the new version issue on jbpm forums?

scott_mathieson
Jun 6th, 2006, 07:53 AM
I don't think there is any easy way out. The code is also dependent on jbpm 3.1.1 (the issue from what I understand doesn't occur on 3.1.0).
Have you discussed the new version issue on jbpm forums?
Hi Costin,

Looking at the jBPM forums it seems like versioning is a topic still under discussion, but the current implementation is working as intended (unfortunately for me). Looks like I'll just have to use my hacked up version until such times as the issue is resolved.

Regards,

Scott

wrschneider99
Jun 6th, 2006, 10:21 AM
Hi Costin,

Looking at the jBPM forums it seems like versioning is a topic still under discussion, but the current implementation is working as intended (unfortunately for me). Looks like I'll just have to use my hacked up version until such times as the issue is resolved.

Regards,

Scott

Taking a closer look at jBPM source code it may be that jBPM is indeed doing the "right thing" for the time being.

If you think about process definitions as persistent objects, it makes sense. Every time you call deployProcessDefinition, you get a new DB row. And because that row persists across restarts, you don't need to deploy the process again unless it changes. So maybe Spring xml config isn't the right place for the process defs in the first place, unless you're dropping the db on every restart.

Now, it would be *nice* if deployProcessDefinition did some kind of deep-compare to see if the process has changed, and redeploy only if necessary. But unnessential.

Costin Leau
Jun 10th, 2006, 03:33 PM
The new Spring Modules 0.4 documents jBPM usage. See https://springmodules.dev.java.net/docs/reference/0.4/html_single/#jbpm31.

Costin Leau
Jun 28th, 2006, 10:22 AM
Now, it would be *nice* if deployProcessDefinition did some kind of deep-compare to see if the process has changed, and redeploy only if necessary. But unnessential.
That could be achieved by providing some sort of process signature or version which can indicate if an update was made or not.
Just an idea...

alcazar
Aug 4th, 2006, 11:41 AM
Hello all -

I would like to determine if a solution has been found to resolve redeploying the process definition on server start-up. I have this issue and have been following this thread to find a resolution.

Costin created a JIRA issue, but the proposed resolution doesn't make sense to me...

http://opensource.atlassian.com/projects/spring/browse/MOD-136

Also, overriding the JbpmTemplate to check for existing process definitions doesn't appear to be a graceful solution to this. Any advise you can offer is greatly appreciated.

Kind Regards,
R. Alcazar

Costin Leau
Aug 5th, 2006, 02:34 PM
The JIRA issue is marked as won't fix - basically there isn't any clean solution that the integration module can provide. As you've seen from the discussions and links on this threads there are various approaches, the easiest one being to create the schema only once and then work with the db without redeploying the process definition.
AFAIK, the JBPM has no means of verifying if a definition has been deployed or doing a merge/resolving the error so there isn't an official way to deal with it.

meeru
Aug 15th, 2006, 10:29 PM
Hi Scott,

I tried to employ your rather useful hack in order to prevent redeployment of process defintions across server restarts. CustomJbpmConfigurationFactoryBean works fine, however, as you mentioned to set the process definition to the Jbpm template manually, i have tried the following:


JbpmTemplate process1Template = (JbpmTemplate) ctx.getBean("jbpmTemplate");

ProcessDefinition def = process1Template.getJbpmConfiguration().createJbpm Context().getGraphSession().findLatestProcessDefin ition("process1");

process1Template.setProcessDefinition(def);

ProcessInstance processInstance = process1Template.getProcessDefinition().createProc essInstance();
processInstance.signal();

process1Template.saveProcessInstance(processInstan ce);


which results in...


WARN [main] JDBCExceptionReporter.logExceptions(71) | SQL Error: 2291, SQLState: 23000
ERROR [main] JDBCExceptionReporter.logExceptions(72) | ORA-02291: integrity constraint (JBPM.FK_PROCIN_ROOTTKN) violated - parent key not found

WARN [main] JDBCExceptionReporter.logExceptions(71) | SQL Error: 2291, SQLState: 23000
ERROR [main] JDBCExceptionReporter.logExceptions(72) | ORA-02291: integrity constraint (JBPM.FK_PROCIN_ROOTTKN) violated - parent key not found

ERROR [main] AbstractFlushingEventListener.performExecutions(30 0) | Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationExcepti on: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert( SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.conver t(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:202)
at org.hibernate.jdbc.AbstractBatcher.prepareStatemen t(AbstractBatcher.java:91)
at org.hibernate.jdbc.AbstractBatcher.prepareStatemen t(AbstractBatcher.java:86)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchSta tement(AbstractBatcher.java:171)
at org.hibernate.persister.entity.AbstractEntityPersi ster.insert(AbstractEntityPersister.java:2048)
at org.hibernate.persister.entity.AbstractEntityPersi ster.insert(AbstractEntityPersister.java:2427)
at org.hibernate.action.EntityInsertAction.execute(En tityInsertAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQue ue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListe ner.performExecutions(AbstractFlushingEventListene r.java:297)
at org.hibernate.event.def.DefaultFlushEventListener. onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.j ava:985)
at org.springframework.orm.hibernate3.HibernateAccess or.flushIfNecessary(HibernateAccessor.java:394)
at org.springframework.orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:367)
at org.springframework.orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:334)
at org.springmodules.workflow.jbpm31.JbpmTemplate.exe cute(JbpmTemplate.java:81)
at org.springmodules.workflow.jbpm31.JbpmTemplate.sav eProcessInstance(JbpmTemplate.java:339)
at org.blah.blah.jbpm.JbpmTest.main(JbpmTest.java:51)
Caused by: java.sql.BatchUpdateException: ORA-02291: integrity constraint (JBPM.FK_PROCIN_ROOTTKN) violated - parent key not found

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateE xception(DatabaseError.java:367)
at oracle.jdbc.driver.OraclePreparedStatement.execute Batch(OraclePreparedStatement.java:8739)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch( BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:195)
... 18 more


and here is my spring context file


<!-- jBPM Configuration -->
<bean id="jbpmConfig" class="org.blah.blah.jbpm.CustomLocalJbpmConfigurationFac toryBean">
<!-- pass in existing sessionFactory -->
<property name="sessionFactory" ref="jbpmSessionFactory"/>
<property name="configuration" value="org/blah/blah/jbpm/jbpm.cfg.xml"/>
<property name="processDefinitions">
<list>
<ref local="process1"/>
</list>
</property>
<property name="createSchema" value="false"/>
</bean>

<bean id="process1" class="org.springmodules.workflow.jbpm31.definition.Proce ssDefinitionFactoryBean">
<property name="definitionLocation" value="org/blah/blah/jbpm/process/process1.xml"/>
</bean>


<!-- jBPM template -->
<bean id="jbpmTemplate" class="org.springmodules.workflow.jbpm31.JbpmTemplate">
<constructor-arg index="0" ref="jbpmConfig"/>
<constructor-arg index="1" ref="process1"/>
</bean>




Any help would be appreciated,

Thanks

meeru

scott_mathieson
Aug 16th, 2006, 04:41 AM
Hi Meeru,

I think the problem you are seeing is due to the fact that you are not performing your updates to the process in the same context as it was created in. If you wrap your create/signal/save in a JbpmCallback it should (I think) solve the problem. e.g.


process1Template.execute(new JbpmCallback() {

public Object doInJbpm(JbpmContext context) {

ProcessInstance inst = context.newProcessInstanceForUpdate("process");
inst.signal();
context.save(inst);
// dummy return
return null;
}
});


This is what I've been using in my implementation and wrapping my interactions with the process/task instances into a callback works for me.

If I'm talking rubbish here then hopefully someone on the forum will correct me.

Regards,

Scott

meeru
Aug 16th, 2006, 02:14 PM
Thanks for the immediate reply, I tried the following:


JbpmTemplate template = (JbpmTemplate) ctx.getBean("jbpmTemplate");

ProcessDefinition def = template.getJbpmConfiguration().createJbpmContext( ).getGraphSession().findLatestProcessDefinition("process1");
template.setProcessDefinition(def);

template.execute(new JbpmCallback() {

public Object doInJbpm(JbpmContext context) {

ProcessInstance inst = context.newProcessInstanceForUpdate("process1");
inst.signal();
context.save(inst);
// dummy return
return null;
}
})


which gives me the following exception:


Exception in thread "main" org.hibernate.SessionException: Session is closed!
at org.hibernate.impl.AbstractSessionImpl.errorIfClos ed(AbstractSessionImpl.java:49)
at org.hibernate.impl.SessionImpl.fireSave(SessionImp l.java:526)
at org.hibernate.impl.SessionImpl.save(SessionImpl.ja va:518)
at org.hibernate.impl.SessionImpl.save(SessionImpl.ja va:514)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.orm.hibernate3.HibernateTempla te$CloseSuppressingInvocationHandler.invoke(Hibern ateTemplate.java:1205)
at $Proxy4.save(Unknown Source)
at org.jbpm.svc.save.HibernateSaveOperation.save(Hibe rnateSaveOperation.java:38)
at org.jbpm.svc.Services.save(Services.java:156)
at org.jbpm.JbpmContext.save(JbpmContext.java:388)
at org.jbpm.JbpmContext.autoSave(JbpmContext.java:586 )
at org.jbpm.JbpmContext.close(JbpmContext.java:137)
at org.springmodules.workflow.jbpm31.JbpmTemplate.rel easeContext(JbpmTemplate.java:111)
at org.springmodules.workflow.jbpm31.JbpmTemplate.exe cute(JbpmTemplate.java:100)


here is my spring config



<bean id="jbpmConfig" class="org.blah.blah.jbpm.CustomLocalJbpmConfigurationFac toryBean">
<!-- pass in existing sessionFactory -->
<property name="sessionFactory" ref="jbpmSessionFactory"/>
<property name="configuration" value="org/blah/blah/jbpm/jbpm.cfg.xml"/>
</bean>

<bean id="jbpmTemplate" class="org.springmodules.workflow.jbpm31.JbpmTemplate">
<constructor-arg index="0" ref="jbpmConfig"/>
</bean>




however, this works like a charm for me:


JbpmConfiguration config = (JbpmConfiguration) ctx.getBean("jbpmConfig");

JbpmContext context = config.createJbpmContext();

ProcessDefinition def = context.getGraphSession().findLatestProcessDefinit ion("process1");

ProcessInstance in = def.createProcessInstance();
ContextInstance cn = in.getContextInstance();
List l = new ArrayList();
l.add("batman");
l.add("joker");
cn.setVariable("list", l);
in.signal();
context.save(in);
context.close();


I am bypassing the jbpm template altogether, I can use the above solution for now, although would love to get the jbpm template working.

Thanks,

meeru

dlevine
Nov 13th, 2006, 06:59 PM
Hello! Is the Spring Modules CVS still the best place to to try and find an example of jBPM 3.1 + Spring configs? Any other suggestions? Just getting stareted and looking for all of the most up to date resources. Thanks!

d

dlevine
Apr 26th, 2007, 01:04 PM
Meeru,

Funny that I replied to this below when I was just starting to use jbpm plus Spring... Now I am in the same boat that you were in with the JBPMUSER.FK_PROCIN_ROOTTKN violation error. Do you have any more insight into this? I am doing the same thing you were, so I will try the solution recommended to you, and the other solution.

The big problem is that the error is not consistantly repeatable -- i have to use dht app for a while before it shows up. So... it's hard for me to do quick fixes and testing.

Anyways, if anyone else working has experienced this and wants to share ideas/suggestions they would be GREATLY appreciated! =D

d

[2007-04-23 13:22:00,087] DEBUG org.hibernate.SQL insert into JBPM_PROCESSINSTANCE (VERSION_, START_, END_, ISSUSPENDED_, PROCESSDEFINITION_, ROOTTOKEN_, SUPERPROCESSTOKEN_, ID_) values (?, ?, ?, ?, ?, ?, ?, ?)
[2007-04-23 13:22:00,103] WARN org.hibernate.util.JDBCExceptionReporter SQL Error: 2291, SQLState: 23000
[2007-04-23 13:22:00,103] ERROR org.hibernate.util.JDBCExceptionReporter ORA-02291: integrity constraint (JBPMUSER.FK_PROCIN_ROOTTKN) violated - parent key not found
------------------ </log snippet> -----------------------------------------


ps: i've been working with the jBPM support staff at RedHat for weeks trying to track this down. I think it has something to do with the Spring integration which is why they are having trouble solving... which matches the ideas suggested in this thread!!

Costin Leau
Apr 27th, 2007, 02:32 AM
dlevine, you could try using JBpm w/o the Spring integration if you think it affects it though that is not the case. If you take a look at the sources, you'll notice that the 'wrapping' layer doesn't do any logic of itself especially not forcing updated on the database.
The database integrity is likely caused by an incomplete operation to the database probably done through Hibernate.
Try turning logging on to see if you could reproduce the problem.. What version of JBPM are you using?