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!