PDA

View Full Version : understanding jbpm 3.0



tobysaville
Jun 6th, 2006, 09:28 AM
Hello,

Im not entirely sure im understanding the implementation of the JBPM 3.0.x spring module. Unfortunately due to other restrictions, I have to use the JBPM 3.0.2 implementation.

I am able to retrieve a JbpmTemplate from the spring application but it seems that the sort of queries available are very limited, with no option getting hold of the session to perform your own queries. Is it necessary to extend JbpmTemplate myself to expose the session?

Also, a new ProcessDefinition is created each time the application is deployed (possibly related to this thread: http://forum.springframework.org/showthread.php?t=23474)

Also, when I try to get my LocalJbpmSessionFactoryBean from the spring application context, I get a class cast expression.
Definition:


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

Instantiation:


LocalJbpmSessionFactoryBean ljsfb = (LocalJbpmSessionFactoryBean)wac.getBean("jbpmSessionFactoryBean");

Error: (ApplicationListener.java:37 is the line above):


java.lang.ClassCastException: org.springmodules.workflow.jbpm30.LocalJbpmSession FactoryBean$SpringJbpmSessionFactory
at com.web.util.ApplicationListener.contextInitialize d(ApplicationListener.java:37)
at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:3692)
at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4127)
at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDirec tory(HostConfig.java:910)
at org.apache.catalina.startup.HostConfig.deployDirec tories(HostConfig.java:873)
at org.apache.catalina.startup.HostConfig.deployApps( HostConfig.java:474)
at org.apache.catalina.startup.HostConfig.start(HostC onfig.java:1118)
at org.apache.catalina.startup.HostConfig.lifecycleEv ent(HostConfig.java:310)
at org.apache.catalina.util.LifecycleSupport.fireLife cycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1020)
at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:718)
at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1012)
at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:442)
at org.apache.catalina.core.StandardService.start(Sta ndardService.java:450)
at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:680)
at org.apache.catalina.startup.Catalina.start(Catalin a.java:536)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:275)
at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:413)

Any clue what im doing wrong? I realise a proxy is created but I don’t know what its class is. I figure if I can access the LocalJbpmSessionFactoryBean, I can access the JbpmSessionFactory and subsequently the JbpmSession.

Please tell me if my approach is way off.

Cheers, toby

tobysaville
Jun 6th, 2006, 11:51 AM
damn. as soon as i posted this, i discovered the JbpmTemplate.execute(JbpmCallBack callBack) method. im sorted now, cheers.

Costin Leau
Jun 8th, 2006, 08:27 AM
Btw, let me know if you try the module on jbpm 3.0.3.

tobysaville
Jun 8th, 2006, 08:55 AM
im using 3.0.2 at the mo, but if i have time, ill upgrade to 3.0.3 and get back to you.

k.pravin
Jul 6th, 2006, 10:41 AM
I am using JBPM 3.0 and i am not able to sort out this problem.
Could you please help me with this?
How do u deal with property "hibernateConfiguration" ?

tobysaville
Jul 6th, 2006, 12:02 PM
define a bean as follows:


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

where "hibernateSessionFactory" is the id of your org.springframework.orm.hibernate3.LocalSessionFac toryBean bean. The &amp; before the id is crucial, as it defines the name as a pointer. or something.

k.pravin
Jul 6th, 2006, 12:25 PM
thanks for the reply.
but what if i dont't want to use hibernateSessionFactory.Instead of that, i can use hibernate.properties.Since sessiofactory is an optional property.In that case what is the value for "hibernateConfiguration"

tobysaville
Jul 6th, 2006, 12:35 PM
im not sure you can have a hibernate configuration bean configured in spring without a session factory configured.

if you dont have your hibernate session factory configured in spring, why do you want to use spring modules for jbpm? the whole point of this module is to inject hibernate sessions into jbpm objects.

Costin Leau
Jul 9th, 2006, 01:31 PM
Toby is right - the whole point of jbpm module is to reuse Spring application beans with jbpm including transaction support. See the official docs (https://springmodules.dev.java.net/docs/reference/0.4/html/jbpm31.html) for more information.

tobysaville
Aug 24th, 2006, 09:55 AM
When i create a process instance, the NAME_ value in my JBPM_MODULEINSTANCE table is null. I imagine this is because the jbpm.properties file isnt being loaded (where the task instance class is defined).

this file is in the root of my classpath in my webapp (WEB-INF/classes/jbpm.properties)

What is the best way to define the properties from this file, when using jbpm 3.0.2 and spring modules?

Also, when building the JbpmSessionFactory in the spring bean context, is it ok to use the constructor or should i use one of the static factory buildJbpmSessionFactory(...) methods?

thanks, tobes

Costin Leau
Aug 28th, 2006, 12:22 AM
I'm not sure what causes the field to be null - if you have to specify the properties file simple do it as you would do without the spring integration (the integration does not affect loading properties files).

As for defining the SessionFactory one should use the LocalJbpmSessionFactoryBean - take a look at its javadoc. The jbpm package is very similar (on purpose) with the integrations from the main Spring distribution (i.e. jdo/hibernate/jpa). The SessionFactory is configured through a FactoryBean while working with the framework itself is done mainly through the Template and Callback classes.

tobysaville
Aug 31st, 2006, 09:28 AM
Hello,

Sorry for the massive code dump, but i just cant see where im going wrong, so i thought i would supply everything.

Basically, i have everything working, except my MODULEINSTANCE_ table doesnt have its foreign key NAME_ value set (as per my previous post). This is set as part of the cascading persistance of the instances field of the ProcessInstance field.

I should also mention that if i handle the session transaction myself (with open, begin, commit, close) then the process instance is saved correctly.

If you can see anything funky below, please let me know. Thanks for your time.

My application context config:


<bean id="hibernateSessionFactoryJbpm"
class="org.springframework.orm.hibernate3.LocalSessionFac toryBean">
<property name="dataSource" ref="dsIntranet"/>

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="hibernate.query.substitutions">true 1, false 0</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.default_schema">dbJBPM.dbo</prop>
</props>
</property>

<property name="mappingJarLocations">
<list>
<value>WEB-INF/lib/jbpm-3.0.4.jar</value>
</list>
</property>
</bean>

<bean id="hibernateConfigurationJbpm"
factory-bean="&amp;hibernateSessionFactoryJbpm"
factory-method="getConfiguration"/>

<bean id="jbpmSessionFactory"
class="org.springmodules.workflow.jbpm30.LocalJbpmSession FactoryBean">
<property name="hibernateConfiguration" ref="hibernateConfigurationJbpm"/>
<property name="hibernateSessionFactory" ref="hibernateSessionFactoryJbpm"/>
<property name="processDefinitions">
<list>
<ref bean="CLAIM_PD"/>
</list>
</property>
</bean>

<bean id="CLAIM_PD"
class="org.springmodules.workflow.jbpm30.definition.Proce ssDefinitionFactoryBean">
<property name="definitionLocation"
value="classpath:com/qas/newmedia/intranet/oem/res/workflow.par/processdefinition.xml"/>
<property name="deployProcessDefinitionOnStartup" value="false"/>
</bean>

<bean id="jbpmTemplate"
class="org.springmodules.workflow.jbpm30.JbpmTemplate">
<constructor-arg index="0" ref="jbpmSessionFactory"/>
<constructor-arg index="1" ref="CLAIM_PD"/>
</bean>

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


And the code in my controller:


jbpmTemplate.execute(new JbpmCallback() {
public Object doInJbpm(JbpmSession context) {

log.debug("getting pd");
ProcessDefinition pd = context.getGraphSession().findLatestProcessDefinit ion("CLAIM_PD");
ProcessInstance pi = pd.createProcessInstance();
pi.signal();
context.getGraphSession().saveProcessInstance(pi);
return null;
}
});

Costin Leau
Sep 1st, 2006, 03:55 AM
Try comparing the logs between this configuration and the one where you do manual management of the transaction - you should find some differences.