cancel
Showing results for 
Search instead for 
Did you mean: 

transaction synchronization

elsarfhem
Champ in-the-making
Champ in-the-making
Hi,
I'm not able to synchronize transtacion among jpa-spring-activity.
In my test case I tried to delete a process AND a JPA entity related to the process. The process was deleted also if the method throw an exception!
 
@Transactional
public void transactionalMethod(){
runtimeService.deleteProcessInstance(id, "");
entityDao.delete(daoInstance);         //<———- this will throw an exception
}

this is my spring-activiti db configuration

<!– ANNOTAZIONI –>
   <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

   <!– DATASOURCE E JPA/HIBERNATE –>
   <jee:jndi-lookup id="dataSource" jndi-name="java:jdbc/cqds" />

   <bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
      <property name="persistenceUnitName" value="ControlloQualitaPU" />
   </bean>

   <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
      <property name="entityManagerFactory" ref="entityManagerFactory" />
   </bean>

   <!– enable the configuration of transactional behavior based on annotations –>
   <tx:annotation-driven transaction-manager="transactionManager" />

   <!– Activiti –>
   <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
      <property name="dataSource" ref="dataSource" />
      <property name="transactionManager" ref="transactionManager" />
      <property name="deploymentResources"
         value="classpath*:it/ipzs/iol/cq/process/autodeploy.*.bpmn20.xml" />
      <property name="databaseSchemaUpdate" value="true" />
      <property name="jobExecutorActivate" value="true" />
      <property name="history" value="full" />
      <!– JPA –>
      <property name="jpaEntityManagerFactory" ref="entityManagerFactory" />
      <property name="jpaHandleTransaction" value="true" />     <!– yet tested with false –>
      <property name="jpaCloseEntityManager" value="true" />   <!– yet tested with false –>
      
   </bean>

   <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
      <property name="processEngineConfiguration" ref="processEngineConfiguration" />
   </bean>

   <bean id="repositoryService" factory-bean="processEngine"
      factory-method="getRepositoryService" />
   <bean id="runtimeService" factory-bean="processEngine"
      factory-method="getRuntimeService" />
   <bean id="taskService" factory-bean="processEngine"
      factory-method="getTaskService" />
   <bean id="historyService" factory-bean="processEngine"
      factory-method="getHistoryService" />
   <bean id="managementService" factory-bean="processEngine"
      factory-method="getManagementService" />
   <bean id="formService" factory-bean="processEngine"
      factory-method="getFormService" />

Do I have to use JTA? It depends from JNDI datasource (deployed through JBoss)?
4 REPLIES 4

meyerd
Champ on-the-rise
Champ on-the-rise
In order to help you, I would need to see your activiti configuration / application context.

Basically this works if you configure it right and use the same datasource for activiti and JPA.
If you want to use different data-sources you need JTA.

elsarfhem
Champ in-the-making
Champ in-the-making
what do you mean? I attached my configuration… I stripped the unnecessary part (like spring security). Is this not enough?
I'm using only one datasource fetched through spring jndi call.
Am I missing something?

I can attached further details about 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="ControlloQualitaPU" transaction-type="RESOURCE_LOCAL">
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
  <non-jta-data-source>java:jdbc/cqds</non-jta-data-source>
  <properties>
   <property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect" />
   <property name="hibernate.hbm2ddl.auto" value="update" />
   <property name="hibernate.archive.autodetection" value="class, hbm" />
   <property name="hibernate.show_sql" value="true" />
   <property name="hibernate.query.substitutions" value="true 1, false 0" />
  </properties>
</persistence-unit>
</persistence>

meyerd
Champ on-the-rise
Champ on-the-rise
Hmm… not sure how I could miss that huge XML snippet Smiley Happy

As I said, basically this works in a single resource context if you make sure that your JPA and activiti work happens in the same JDBC connection.

Unless someone else can see what's wrong with this, could you assemble a simple testcase and attach it to this thread?
And add information on you environment, app server, version etc?

elsarfhem
Champ in-the-making
Champ in-the-making
sorry, at the moment I have no time to make a simple test case… I have to release my project… Delivery is really near.

could it depends on these parameters?

<property name="jpaHandleTransaction" value="true" />     <!– yet tested with false –>
<property name="jpaCloseEntityManager" value="true" />   <!– yet tested with false –>

What should supposed to be the correct settings with JSF/Spring/JPA? Both false?