Process with a service Task that query mysql database

764 views
Skip to first unread message

mireill...@gmail.com

unread,
Feb 20, 2015, 3:20:35 AM2/20/15
to camunda-...@googlegroups.com
Hallo everyone,

I am having a problem to execute a sevice Task, which query MySQL database. The process is failing to be deployed. I am using the the JBoss AS 7 based distribution. Below are the steps that I have followed based on the camunda documentation (worthy to note that I am new to Camunda). Can you please tell me what is still missing in the code that I can programmarically execute the process and let the service Task executes the retrieveAllStudents from mysql database.

Step1: Connect JBOSS with the mysql DB. This step was successful and an excerpt of the standalone.xml is the following:
**********************************
<datasource jta="true" jndi-name="java:jboss/datasources/ProcessEngine" pool-name="ProcessEngine" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:h2:./camunda-h2-dbs/process-engine;DB_CLOSE_DELAY=-1;MVCC=TRUE;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource jta="false" jndi-name="java:/mysql" pool-name="MySQLDS" enabled="true" use-ccm="false">
<connection-url>jdbc:mysql://localhost:3307/camundademo</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password>s2e</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
<drivers>
<driver name="mysql" module="com.mysql">
<driver-class>com.mysql.jdbc.Driver</driver-class>
</driver>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
*******************************

Step2: Add the dependencies in the pom.xml
***********************
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tutorials.camunda</groupId>
<artifactId>camunda-ap</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>war</packaging>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-bom</artifactId>
<version>7.2.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- camunda engine dependency -->
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-engine</artifactId>
<scope>provided</scope>
</dependency>

<!-- camunda cdi beans -->
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-engine-cdi</artifactId>
</dependency>

<!-- provides a default EjbProcessApplication -->
<dependency>
<groupId>org.camunda.bpm.javaee</groupId>
<artifactId>camunda-ejb-client</artifactId>
</dependency>

<!-- Java EE 6 Specification -->
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-web-6.0</artifactId>
<version>3.0.2.Final</version>
<type>pom</type>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>xalan</artifactId>
<groupId>xalan</groupId>
</exclusion>
</exclusions>
</dependency>

</dependencies>

<build>
<finalName>camunda-ap</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
****************************

Step3: Add the WEB-INF/beans.xml, the META-INF/persistence.xml and the META-INF/processes.xml

***************WEB-INF/beans.xml******
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" bean-discovery-mode="all">
</beans>

******************META-INF/persistence.xml*********
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

<persistence-unit name="camunda-ap" transaction-type="JTA">
<jta-data-source>java:/mysql</jta-data-source>
<class>tutorials.camunda.Student</class>
<properties>

<!-- Properties for Hibernate -->
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>

</properties>
</persistence-unit>
</persistence>

**********processes.xml to configure and bootstrap the process engine ******
<process-application
xmlns="http://www.camunda.org/schema/1.0/ProcessApplication"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<process-archive name="camunda-ap">
<process-engine>default</process-engine>
<properties>
<property name="isDeleteUponUndeploy">true</property>
<property name="isScanForProcessDefinitions">true</property>
</properties>
</process-archive>

</process-application>

Step4: This is an excerpt of the service Task of the process 'queryProcess'
***********
<bpmn2:process id="queryProcess" name="Query Process" isExecutable="true">
<bpmn2:serviceTask id="QueryServiceTask" camunda:expression="#{StudentBean.retrieveAllStudents()}" name="Query MySql Database">
**********************

Step5: Create the required classes

***********************Student***************
@Entity
@Table(name="STUDENT")
public class Student implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="id", precision=0)
private Long id=null;
@Column(name="student_name", nullable=false)
private String studentName;

//getters and setters

*****************IStudentBean**********
@Local
public interface IStudentBean {
void saveStudent(Student student);
Student findStudent(Student student);
List<Student> retrieveAllStudents();
}

********************************StudentBean**********
@Stateless
@Named
public class StudentBean implements IStudentBean{
@PersistenceContext(unitName = "camunda-ap")
private EntityManager entityManager;
public StudentBean(){}
@Override
public void saveStudent(Student student){
entityManager.persist(student);
}
@Override
public Student findStudent(Student student) {
Student student1 = entityManager.find(Student.class, student.getId());
return student1;
}
@Override
public List<Student> retrieveAllStudents() {

String q = "SELECT p from " + Student.class.getName() + " p";
Query query = entityManager.createQuery(q);
@SuppressWarnings("unchecked")
List<Student> students = query.getResultList();
return students;
}
}

Thank you in advance for your answers!

thorben....@camunda.com

unread,
Feb 20, 2015, 3:22:21 AM2/20/15
to camunda-...@googlegroups.com, mireill...@gmail.com
Hi,

What is the error you get?

Cheers,
Thorben

Ingo Richtsmeier

unread,
Feb 20, 2015, 3:49:51 AM2/20/15
to camunda-...@googlegroups.com, mireill...@gmail.com
Hi, try studentBean.retrieveAllStudents() (with lower case 's').

Kind Regards, Ingo

mireill...@gmail.com

unread,
Feb 20, 2015, 4:48:01 AM2/20/15
to camunda-...@googlegroups.com, mireill...@gmail.com
Hallo Thorben,

when I try to start the process from the Tasklist, I am getting the following error: The process could not be started. : Cannot instantiate process definition queryProcess:1:7ff050ad-b8e3-11e4-b3b6-063820524153: Unknown property used in expression: #{StudentBean.retrieveAllStudents()}. Cause: Cannot resolve identifier 'StudentBean'

In the server.log, I am getting the following error:
SEVERE [org.camunda.bpm.engine.impl.interceptor.CommandContext] (http-/127.0.0.1:8080-1) Error while closing command context: org.camunda.bpm.engine.ProcessEngineException: Unknown property used in expression: #{StudentBean.retrieveAllStudents()}. Cause: Cannot resolve identifier 'StudentBean'
at org.camunda.bpm.engine.impl.el.JuelExpression.getValue(JuelExpression.java:55) [camunda-engine-7.2.0.jar:7.2.0]
at org.camunda.bpm.engine.impl.bpmn.behavior.ServiceTaskExpressionActivityBehavior.execute(ServiceTaskExpressionActivityBehavior.java:45) [camunda-engine-7.2.0.jar:7.2.0]
at org.camunda.bpm.engine.impl.pvm.runtime.operation.PvmAtomicOperationActivityExecute.execute(PvmAtomicOperationActivityExecute.java:42) [camunda-engine-7.2.0.jar:7.2.0]
at org.camunda.bpm.engine.impl.pvm.runtime.operation.PvmAtomicOperationActivityExecute.execute(PvmAtomicOperationActivityExecute.java:27) [camunda-engine-7.2.0.jar:7.2.0]
at org.camunda.bpm.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:129) [camunda-engine-7.2.0.jar:7.2.0]
at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:450) [camunda-engine-7.2.0.jar:7.2.0]
at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:440) [camunda-engine-7.2.0.jar:7.2.0]
at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:420) [camunda-engine-7.2.0.jar:7.2.0]

Cheers,

Mireilla Smith

unread,
Feb 20, 2015, 4:51:58 AM2/20/15
to camunda-...@googlegroups.com
Please find attached the serverlog.

Best 
ServerLog.txt

Mireilla Smith

unread,
Feb 20, 2015, 5:18:26 AM2/20/15
to camunda-...@googlegroups.com
Hallo Ingo, 

sorry but I didn't understand your suggestion, where should I use  studentBean.retrieveAllStudents() ?

Best

--
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/f0bRzY_YM6s/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/8af18545-9fbf-45e7-87eb-3d9d6b6fb564%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

mireill...@gmail.com

unread,
Feb 20, 2015, 6:24:47 AM2/20/15
to camunda-...@googlegroups.com, mireill...@gmail.com
Hallo Ingo,

after looking to this post: https://groups.google.com/forum/#!searchin/camunda-bpm-users/cdi$20injection/camunda-bpm-users/M7K3KXiEHaA/Ni5ROF-Lu1QJ
I understood what you meant and evrything worked fine.
Thank you so much!

Best
Reply all
Reply to author
Forward
0 new messages