Camunda BPM Platform with JPA?

1,788 views
Skip to first unread message

Fer

unread,
Feb 3, 2014, 10:23:02 AM2/3/14
to camunda-...@googlegroups.com
Hello,

I'm trying to use JPA with Camunda, as I was using with Activiti until I discovered Camunda. Unluckily, I cannot find any example on Internet about this, so I wanted to ask if any of you knows about a complete example of this to learn how it should work. If that's not possible, what changes should we add to the working Activiti configuration in order to make it work?

I must say that migration from Activiti with JPA to Camunda with JPA could be an interesting and useful topic in your migration guide, by the way.


Thanks a lot for your time. Regards.

Roman Smirnov

unread,
Feb 3, 2014, 11:33:44 AM2/3/14
to camunda-...@googlegroups.com
Hi Fernando,

You do not have to migrate anything to use camunda BPM together with JPA. So, if it worked with Activiti it should also work with camunda BPM. The following properties should be set in you engine configuration xml:


<property name="jpaPersistenceUnitName" value="activiti-jpa-pu" />
<property name="jpaHandleTransaction" value="true" />
<property name="jpaCloseEntityManager" value="true" />
 

These properites are the same in Activiti!

Do have some issues using camunda BPM with JPA?

Cheers,
Roman

Fer

unread,
Feb 5, 2014, 4:52:53 AM2/5/14
to camunda-...@googlegroups.com
Hello Roman,

I'm new to both Camunda and Java EE, Spring and JPA and somehow it's not working for me. With no examples where to learn from, I'm really stucked. I managed back then to make it work with Activiti, but after refactoring the code for Camunda, with huge changes in code structure, files and more things, it doesn't work for me. The deployment gets wrong with some errors that don't indicate why.

In my case, for those wondering, I use in a small workflow a Service Task with an expression that calls an entity service to persist that entity. It's not very complicated, in fact, but I don't know how to continue. As I said, a brief example of a project using JPA with Camunda and Spring would be of great help. Could anybody show the file structure and configuration of a working project like this in order to reproduce it?

Thanks for your time.

Roman Smirnov

unread,
Feb 5, 2014, 8:07:42 AM2/5/14
to camunda-...@googlegroups.com
Hi Fernando,

Unfortunately, we do not have any documentation about using camunda with JPA and Spring.

Maybe you could provide your stacktraces to have a look at it.

Furthermore, the test suite of engine-spring module provide some test cases, how to configure and to use camunda BPM with Spring and JPA:


I hope that helps you to configure your process application with JPA and Spring?

Cheers,
Roman

Fer

unread,
Feb 6, 2014, 8:08:59 AM2/6/14
to camunda-...@googlegroups.com

Hello, Roman,

Using JUnit tests my project works as expected, persisting entities through their services and so on, but when I try to deploy the .war file to Tomcat, I get the following errors. I can't copy them from Tomcat's command window (I'm working right now on Windows), so I attach the snapshots:


Hello, Roman,

Using JUnit tests my project works as expected, persisting entities through their services and so on, but when I try to deploy the .war file to Tomcat in order to use it with the Tasklist, I get the following errors. I can't copy them from Tomcat's command window (I'm working right now on Windows), so I attach the snapshots. I apologize for it:

1st and 2nd



3rd and 4th

5th



What I've found is this JIRA issue some weeks ago, but I'm not sure if it's related, since I'm not redeploying the application.

I also attach files that may be helpful. I could attach more if needed. Do you have any clue about this errors? Thanks for your help.


Kind regards.
applicationContext.xml
customerProcess.bpmn
jpa-persistence.xml
pom.xml

Christian Lipphardt

unread,
Feb 6, 2014, 8:54:27 AM2/6/14
to camunda-...@googlegroups.com
Hi Fer,

Please have a look into the TOMCAT_HOME/logs/localhost.log file and post the exception here or attach the log. There must be something because I saw on your screenshots the message 'SEVERE Error listenerStart' on image 1 and 5.

Did you try to set your Spring Version to 3.1.2-RELEASE instead of 4.0.0? I do not know if we are compatible with 4.x.

Cheers,
Christian

Fer

unread,
Feb 6, 2014, 9:02:09 AM2/6/14
to camunda-...@googlegroups.com
Hi Christian,

I don't know why, but the logs are not updated with these deployments, so I don't have anything. I had already check that...

About the version, I've tried the 3.1.2.RELEASE (3.1.2-RELEASE would give me errors), but I get the same error.


Do you need the whole code to check it?


Thanks.

Christian Lipphardt

unread,
Feb 6, 2014, 9:24:11 AM2/6/14
to camunda-...@googlegroups.com
Hi Fer,

Mhm, strange that you do not have anything in the logs. The whole code / WAR archive would help us I think. Would be cool if you could provide it to us.

Cheers,
Christian

Fer

unread,
Feb 6, 2014, 10:25:12 AM2/6/14
to camunda-...@googlegroups.com
Hello,

I attach the source code to the email. The generated war was too large to do it. Now maybe you can reproduce my problem. Thanks!

PS: Google doesn't allow me to upload it as a .zip file, sorry for the .rar file.
embedded-form-example.rar

Christian Lipphardt

unread,
Feb 6, 2014, 1:17:24 PM2/6/14
to camunda-...@googlegroups.com
Hi Fer,

The problem is there is a ClassNotFoundException regarding javax.persistence.EntityManagerFactory.
It is bundled together with Hibernate inside your WAR as hibernate-jpaxxxxxx, but somehow the Engine is not able to find it when initializing the ProcessEngineConfiguration.
When I dropped the JAR into Tomcat's lib folder, it worked.
I need to investigate it further tomorrow, but now you have a workaround.

Cheers and good night,
Christian

Fer

unread,
Feb 7, 2014, 3:26:09 AM2/7/14
to camunda-...@googlegroups.com
Hello Christian,

Thanks for taking a look to this issue. I've tried what you said, but it's not working for me as a workaround. I copied hibernate-jpa-2.1-api-1.0.0.FINAL.jar from file.war/WEB-INF/lib to /tomcat/lib/, restarted the server and deploy the .war file and I got exactly the same error. If you have more clues about this, I'd appreciate it so I can continue working with it.

Also, I hope this post can help people in the same situation.


Cheers.

Fer

unread,
Feb 7, 2014, 3:30:16 AM2/7/14
to camunda-...@googlegroups.com
Sorry for the second email, just to give more information. I also tried to copy the .jar file into /tomcat/server/apache-tomcat-7.0.35/lib, but didn't work either.

Christian Lipphardt

unread,
Feb 7, 2014, 3:45:00 AM2/7/14
to camunda-...@googlegroups.com

Hi Fer,

The second path is the correct one. Also remove the Jar from your WAR deployment.

I also changed the h2 path in the persistent.xml file to in-memory: jdbc:h2:mem:camunda and the hibernate dialect to H2Dialect instead of the HSQL one.

This was all I did change.

Cheers
Christian

--
You received this message because you are subscribed to a topic in the Google Groups "camunda BPM users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/camunda-bpm-users/SIQNwhXLDN0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/camunda-bpm-users/227dd809-bc69-497f-b6ed-d2114f779cc5%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Fer

unread,
Feb 7, 2014, 4:30:10 AM2/7/14
to camunda-...@googlegroups.com
Hello,

I've left just one jar in /tomcat/server/apache-tomcat-7.0.35/lib, changed my jpa-persistence.xml according to the data you said, opened the .war file, deleted WEB-INF/lib/hibernate-jpa-2.1-api-1.0.0.FINAL.jar, deployed the modified .war file and still not working. Did I miss something during the process?


Regards.

Christian Lipphardt

unread,
Feb 7, 2014, 6:10:01 AM2/7/14
to camunda-...@googlegroups.com
Hi Fer,

I checked it again and improved some things:

persistence.xml (jpa-persistence.xml):

replaced <provider>org.hibernate.ejb.HibernatePersistence</provider> with <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
replaced <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" /> with <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
replaced <property name="hibernate.connection.url" value="jdbc:h2:tcp://localhost/test;DB_CLOSE_ON_EXIT=FALSE" /> with <property name="hibernate.connection.url" value="jdbc:h2:mem:camunda;DB_CLOSE_ON_EXIT=FALSE" />

DemoProcessApplication.java:

replaced 'extends ServletProcessApplication' with 'extends SpringServletProcessApplication'

This class is only required if you want to do some things like doing custom registration stuff after deployment etc...

applicationContext.xml:

added    

<!-- rename the engine otherwise it is called "default" and clashes with the default one -->
<property name="processEngineName" value="SpringJPAProcessEngine" />

to the SpringProcessEngineConfiguration otherwise it will start up as default which already exists.

changed
 <bean id="processEngine" class="org.camunda.bpm.engine.spring.ProcessEngineFactoryBean">
to
<bean id="processEngine" class="org.camunda.bpm.engine.spring.container.ManagedProcessEngineFactoryBean">
because we need to register the engine with the platform to use tasklist / cockpit

And I did the JPA.jar thing by deleting hibernate-jpa-2.1-api-1.0.0.Final.jar from the WAR and moving it to CAMUNDA-HOME/server/apache-tomcat-7.0.35/lib

Then the application works for me.

I attached the fixed project as a zip.

Cheers
Christian


embedded-form-example-fixed.zip

Fer

unread,
Feb 7, 2014, 7:20:43 AM2/7/14
to camunda-...@googlegroups.com
Thank you so much for all the tips. Anyway, I tried my project with your changes and then your whole zip file, and somehow in my current configuration the project is not working either and I'm getting again the same errors. Tests are doing fine also in your fixed version, and I don't think I'm doing anything different from what you say, so I'll try to reinstall tomcat with the platform and see if I still have them.

I will keep you posted. Cheers.

Christian Lipphardt

unread,
Feb 7, 2014, 7:39:14 AM2/7/14
to camunda-...@googlegroups.com
Hi Fer,

I just used the camunda-bpm tomcat 7.1.0-alpha2 at
http://www.camunda.org/release/camunda-bpm/tomcat/7.1/camunda-bpm-tomcat-7.1.0-alpha2.zip
.
No modifications except those ones I described to you.

Cheers,
Christian


Fer

unread,
Feb 7, 2014, 9:13:23 AM2/7/14
to camunda-...@googlegroups.com

Hello one more time,

I've deleted my current installation of camunda-bpm-tomcat-7.1.0-alpha2 and I've re-installed it. Before starting it, I added to /tomcat/server/apache-tomcat-7.0.35/lib the hibernate-jpa .jar. Afterwards, I started the server by launching start-camunda.bat in root folder. Everything is fine.

Now I added (deployed) the modified .war file (built from your zip project) into the /webapps folder. It gets deployed and now in my Tasklist window, in the top navbar, I can choose between engines: default and SpringJPAProcessEngine. I create a new user account for that engine and it start a process instance. The first step it's ok, but when it tries to load the embedded form, I get the following error:


Looking at the "net console" of Firebug, this request is sent twice:

http://localhost:8080/camunda/api/engine/engine/SpringJPAProcessEngine/task/15/form

* Request
GET /camunda/api/engine/engine/SpringJPAProcessEngine/task/15/form HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost:8080/camunda/app/tasklist/SpringJPAProcessEngine/
Cookie: JSESSIONID=37188457618CB88FD42EEDFFB119B1F4; phpbb3_3ttd9_k=16e08cb9c52cb918; style_cookie=printonly; phpbb3_3ttd9_u=2; phpbb3_3ttd9_sid=facbec041ad8335246eeea564351911f; phpbb3_cs9tq_k=; _ga=GA1.1.362635566.1379542963; __utma=111872281.362635566.1379542963.1386628483.1389188365.3; __utmz=111872281.1380898305.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); phpbb3_7t3ko_k=bd90837a7d02ec3c; phpbb3_7t3ko_u=2; phpbb3_7t3ko_sid=c7b110e37bc7237912810441ac6fa674; phpbb3_cs9tq_u=2; phpbb3_cs9tq_sid=e8c8cd33a4c1c79bb64b06c89c7e7ced; phpbb3_jat4u_k=6e920a1f58258c36; phpbb3_jat4u_u=48; phpbb3_jat4u_sid=610a89d1bcb9d789de9c5ca505eb11dc
Connection: keep-alive


* Response header:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Authorized-User: demodemo
X-Authorized-Engine: SpringJPAProcessEngine
X-Authorized-Apps: cockpit,admin,tasklist
Cache-Control: no-cache
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 07 Feb 2014 14:09:36 GMT

* Response body:
{"key":"embedded:app:customer-form.html","contextPath":null}


Why is this caused? Is it related to this topic? It seems that somehow it cannot find the form in the deployed webapp folder, but it's on root (I also tried to copy it in other folders). Does it happens to you?


Thanks again.

Fer

unread,
Feb 10, 2014, 3:50:35 AM2/10/14
to camunda-...@googlegroups.com
Hi,

I'm getting a very similar (if not the same) issue like the one I posted here:
https://groups.google.com/forum/#!topic/camunda-bpm-users/nj1CCirMbzM

I've tried different browsers (with and without incognite-mode), because maybe any add-on was messing around, but it's still not loading the form. Chrome's console says something like I'm trying "to do a XMLHttpRequest crossdomain".

Anyway, it may be related to something with this thread, since I just can deploy the war file in a fresh tomcat installation. Otherwise, I still get the same errors below. May it be related to my Java version or whatever?

Thanks again.

Fer

unread,
Feb 10, 2014, 3:55:04 AM2/10/14
to camunda-...@googlegroups.com
Sorry for double posting. Actually, the deployment is working not just with a fresh installation but also after restarting the whole server. I was checking a previous version of the war file, my apologies.

Christian Lipphardt

unread,
Feb 10, 2014, 4:48:10 AM2/10/14
to camunda-...@googlegroups.com
Hi Fer,

So your deployment problem is solved?

Regarding the "XMLHttpRequest crossDomain"-issue, you could try to
implement a solution like described in
https://groups.google.com/forum/#!msg/camunda-bpm-users/9pDJ7rMxFkc/2EHcFM4nbsYJ
. Adding a CORS filter which is already built in into Tomcat as far as I
can tell.

Cheers
Christian

Christian Lipphardt

unread,
Feb 10, 2014, 5:07:53 AM2/10/14
to camunda-...@googlegroups.com
Sorry for the weird text layout, somehow Thunderbird did not work correctly.

Cheers
Christian

Fer

unread,
Feb 10, 2014, 5:17:54 AM2/10/14
to camunda-...@googlegroups.com
Good morning, Christian,

The deployment's issue is temporary resolved, since I can restart the server the whole server and the deployment is fine as far as I know, but it's annoying to have to do this every time and not just copy the .war file into the webapps folder. Especially not knowing why, because the issue/bug can re-appear in another form in the future.

Anyway, the form is not loaded whenI execute the second task of the system. I tried the solution you linked, but then I got a ClassNotFoundError for org.apache.catalina.filters.corsfilter. I tried this from StackOverflow and some possible similar configurations, but not working either and I can't deploy it:
http://stackoverflow.com/questions/15004822/java-lang-classnotfoundexception-org-apache-commons-lang-exception-nestablerunt

On the other hand, has the form ever worked for you in your previous test for the deployment? Maybe you just tried to deploy, saw that was deploying, but didn't test it in the tasklist app. If this is the case, could you check if it's working for you? Why wouldn't it work for me then?


Regards.

Christian Lipphardt

unread,
Feb 10, 2014, 6:42:00 AM2/10/14
to camunda-...@googlegroups.com
Hi Fer,

You were right. The application just deployed, but the forms did not work. I fixed the forms by removing the DemoProcessApplication class from the project and just referenced a SpringServletProcessApplication in the applicationContext.xml. Together with the declaration of the target process engine inside the processes.xml it works now.

See attached project. (Be aware that is broke the unit test with a NPE. Just add a test applicationContext.xml without the SpringServletProcessApplication bean)

The Hot-Deployment error you get for redeploying Spring applications is already filed in our Jira.

Regarding the CORS filter, I am sorry, I just read that is it only available since 7.0.41+. Maybe you can try this one https://bitbucket.org/jsumners/corsfilter/wiki/Home or wait for the next alpha release at february 24th. I think I will upgrade the Tomcat to latest release version for it.


Cheers
Christian

Fer

unread,
Feb 10, 2014, 6:58:22 AM2/10/14
to camunda-...@googlegroups.com
Thank you so much for taking a look to it. I've tried the changes you suggested but I think something is missing. You also forgot to attach the project, so I can't take a look by myself.

About the CORS filter, I guess I don't need it anymore since it isn't necessary according to what you have first said, right?


Cheers.

Christian Lipphardt

unread,
Feb 10, 2014, 7:07:34 AM2/10/14
to camunda-...@googlegroups.com
My Bad!


embedded-form-example-fixed2.zip

Fer

unread,
Feb 10, 2014, 8:20:04 AM2/10/14
to camunda-...@googlegroups.com

Thank you so much, it's finally working!

But my issues are not finished yet. Since they are somehow related, I will not open a new thread, so those having the same issues can resolve all of them at the same time.

Everything seems to work fine now. After using the form, I can persist the entity Customer using an expression and we store as "resultVariable" the created entity. Checking cockpit to monitorize the values that variables are set, I realized that "customer" variable said:




Executing the last task, the value of the form input is not the name gotten from "customer" variable, but just "value", and a message appears:

Server Error: Couldn't deserialize object in variable 'customer'

 I checked on these forums and I've found the following:

Embedded task forms do not yet support complex (serializable) objects.

https://groups.google.com/d/msg/camunda-bpm-users/5L_PtEI0ej0/OuDttNmvnRcJ

Is there any way to make it work, or what workarounds can we use for this? Is it going to be added soon? Thank you so much, one more time.


Best regards.

On Monday, 10 February 2014 13:07:34 UTC+1, Christian Lipphardt wrote:
My Bad!


Christian Lipphardt

unread,
Feb 10, 2014, 8:35:18 AM2/10/14
to camunda-...@googlegroups.com
Hi Fer,

The issue https://app.camunda.com/jira/browse/CAM-1419 covers the usage of custom types for cockpit and is planned for v7.1.
Supprt for embedded forms for 7.1 is still being discussed.

Cheers
Christian

Fer

unread,
Feb 11, 2014, 4:29:45 AM2/11/14
to camunda-...@googlegroups.com
Hello,

(Almost finished!) Since we need to store complex data as variables and this is not possible to do directly so far, would you recommend using data in json/xml format or doing it in any other way?

Somehow it's related to this topic:
https://groups.google.com/d/msg/camunda-bpm-users/87fXChRhT5E/sZyZXkj8DzEJ
 
And also to a lot of discussions like these ones:
https://app.camunda.com/confluence/display/BestPractices/Data+in+Processes
https://groups.google.com/forum/#!msg/camunda-bpm-users/KDLIEUEyb6E/BjivXMSOUJ0J


Thanks a lot. I hope this whole thread is useful for somebody too. Cheers.

Christian Lipphardt

unread,
Feb 11, 2014, 9:26:40 AM2/11/14
to camunda-...@googlegroups.com
Hi Fer,

I think the consent of these topics / slides are that the best approach
is to separate business domain entities from process variables.
Generally we advice to store just a reference of a business domain
entity and fetch it when it is required.
When you want to work around the current issue with complex datatypes,
you can use json / xml based entities which are stored inside the
variable table. But remember to increase the size of these columns, the
default value is 4000 bytes for char/varchar/text columns.

Cheers
Christian


Milan Agatonovic

unread,
Mar 20, 2014, 7:14:44 PM3/20/14
to camunda-...@googlegroups.com
Hello, I am trying to make JPA sample provided above work with camunda tomcat server, but I keep getting 

20 Mar 2014 23:59:38,709 [localhost-startStop-1] ERROR org.springframework.web.context.ContextLoader:318 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'processEngine': FactoryBean threw exception on object creation; nested exception is java.lang.NoClassDefFoundError: javax/persistence/EntityManagerFactory

Also Unit tests in this project fail with:
Caused by: java.lang.NullPointerException
at org.camunda.bpm.engine.spring.application.SpringServletProcessApplication.afterPropertiesSet(SpringServletProcessApplication.java:45)

Is there any working spring JPA process web application or suggestion how I can solve the problems above?

What I am trying to test is how ServiceTask with JavaDelegate that has autowired EntityManager can persist data into the db via map/hibernate.
ServiceTask is after UserTask where entity fields are specified.

Thanks,
Milan

Fer

unread,
Mar 21, 2014, 3:37:17 AM3/21/14
to camunda-...@googlegroups.com
Hello, Milan,

I think you're trying to do what I've already done with the help of this forum and took a while. You have your answer here, correct me if I'm wrong:

https://groups.google.com/d/msg/camunda-bpm-users/VhimSnPPCwg/uMQCPAp9V14J


Kind regards.
Reply all
Reply to author
Forward
0 new messages