Looking for a JavaEE Architect or Potential Tech Co-Founder?
Please don't hesitate to contact me.

How to run Activiti in Glassfish/Postgresql in JTA mode

What you need:
1.) Glassfish

2.) Postgresql - make sure that max_transactions is set to at least 10. Otherwise you will encounter the no session error because by default the value is 0.

3.) Checkout travelexpenses from:
https://svn.camunda.com/fox/demo/activiti-cdi/travelexpenses/trunk/

4.) Modify the following files as follows:
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="activitiPU">
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
  <!-- If you are running in a production environment, add a managed data 
   source, the example data source is just for proofs of concept! -->
  <jta-data-source>activitiDemoDS</jta-data-source>

  <class>com.camunda.fox.activiti.cdi.example.travelexpenses.domain.Employee</class>

  <properties>
   <!-- Properties for Hibernate -->
   <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
   <property name="hibernate.connection.<" value="org.postgresql.Driver" />
   <property name="hibernate.hbm2ddl.auto" value="update" />
   <property name="connection.autocommit" value="true" />
   <property name="hibernate.show_sql" value="false" />
   <property name="hibernate.format_sql" value="false" />
  </properties>
 </persistence-unit>
</persistence>

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


 <!-- activiti configuration for glassfish application server -->

 <!-- lookup the JTA-Transaction manager -->
 <bean id="transactionManager" class="org.springframework.jndi.JndiObjectFactoryBean">
  <property name="jndiName" value="java:appserver/TransactionManager"></property>
  <property name="resourceRef" value="true" />
 </bean>

 <!-- process engine configuration -->
 <bean id="processEngineConfiguration" class="org.activiti.cdi.CdiJtaProcessEngineConfiguration">
  <property name="dataSourceJndiName" value="activitiDS" />
  <property name="transactionManager" ref="transactionManager" />
  <property name="transactionsExternallyManaged" value="true" />
  <property name="databaseSchemaUpdate" value="true" />
 </bean>
</beans>

5.) Make sure that you have successfully define the following inside Glassfish:
Connection Pools
-activitiPool
-activitiDemo
Pool JDBC Connection
-activitiDS
-activitiDemoDS

6.) Since we have 2 PersistenceContext, in AuthenticationBean make sure that you specify unitName when injecting entity manager:

@PersistenceContext(unitName = "activitiPU")
private EntityManager entityManager;
How to run Activiti in Glassfish/Postgresql in JTA mode How to run Activiti in Glassfish/Postgresql in JTA mode Reviewed by Edward Legaspi on Saturday, December 01, 2012 Rating: 5

No comments:

Powered by Blogger.