<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Create JPA entity in service task in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/create-jpa-entity-in-service-task/m-p/64095#M40355</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok, thanks for your time. Here is a short description of my app environment:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Activiti is booted using a singleton EJB which i can inject via @EJB to the &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;managed JSF beans and the app uses JTA with a MySQL datasource. For Activiti the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;datasource and the transaction manager are lookup up via JNDI and configured &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;using JtaProcessEngineConfiguration.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To be honest, i think i mixed up things on transaction handling a lot. I started&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;off with a small JSF webapp to display the deployed process definitions, upload&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and deploy new process definitions, start new process instances and examine the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;task list for the logged in user and the groups he is a member of. The formKey&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;of the startTask and userTasks are used to specify the corresponding JSF form&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;which uses @ManagedBean or @Named beans, and the serviceTask uses normal Java&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;classes for some business logic. The startForms managed bean sets the form&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fields to process variables and then starts a process instance.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Without persistence other then using simple Java objects as process variables &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;everything works fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then i tried to create a JPA entity in the first serviceTask just to see if it&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;is possible to work with JPA persistence within serviceTasks and stored it as&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;process variable as well. The JPA entity i created with an statelss EJB which i &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;looked up via JNDI as well, because i did not find another possibility to get to &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;an persistemce contest within an serviceTask (JavaDelegate). I thought this might&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;be a reaonable use case because this way i can place business logic in reusable &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;session beans. From the next serviceTask in the execution chain i tried to modify&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;the process variable and investigate its modification in the database, because i &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;assumed that Activiti might update this JPA process variable, not only in the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;store for its process variables but in the entities database table as well. But&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;unfortunately this is not the case. When i reload this entity using the stateless&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;session bean then i can only read the initial created entity bean.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then i tried to create the JPA entity from the JSF managed bean already with data&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from the JSF form and set it as process variable when i start off the process &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;instance (opposite to creating the entity from within the first serviceTask).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But too it is not possible to read the entity between the serviceTasks from the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;process variable and the session bean so it reflects the same value. From the &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;stack trace i saw during my debugging sessions i have the impression that a &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;process instance is executed the whole execution path all the way through till&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;the process instance arrives at a wait state? E.g. a userTask? Is this the moment&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;the process variables are persisted to the database? And is this the moment a &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;transaction in the Activiti world ends? At least i think so, but i dont know it&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;yet.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, i think my problem is that i am not able to integrate transaction handling&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;between the stateless session bean and Activiti. I thought JTA on Activiti's &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and the EJB's side will do the trick, but i am not sure if i am using it the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;right way. I dont know too if i need to configure Activiti in a way, besides the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;datasource and the transaction manager, so it is aware of the JPA persistence&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;unit to be able to handle JPA process variables.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;activiti.cfg.xml:&lt;/SPAN&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt; &amp;lt;jee:jndi-lookup jndi-name="jdbc/MysqlErp" id="dataSource" /&amp;gt;&lt;BR /&gt; &amp;lt;jee:jndi-lookup jndi-name="java:appserver/TransactionManager" id="transactionManager" /&amp;gt;&lt;BR /&gt; &amp;lt;bean id="processEngineConfiguration"&lt;BR /&gt;&amp;nbsp; class="org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration"&amp;gt;&lt;BR /&gt;&amp;nbsp; &amp;lt;property name="dataSource" ref="dataSource" /&amp;gt;&lt;BR /&gt;&amp;nbsp; &amp;lt;property name="transactionManager" ref="transactionManager"/&amp;gt;&lt;BR /&gt;&amp;nbsp; &amp;lt;property name="transactionsExternallyManaged" value="true" /&amp;gt;&lt;BR /&gt;&amp;nbsp; &amp;lt;property name="databaseSchemaUpdate" value="true" /&amp;gt;&lt;BR /&gt;&amp;nbsp; &amp;lt;property name="databaseType" value="mysql" /&amp;gt;&lt;BR /&gt;&amp;nbsp; &amp;lt;property name="jobExecutorActivate" value="false" /&amp;gt;&lt;BR /&gt; &amp;lt;/bean&amp;gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;StartBean:&lt;/SPAN&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;@Named&lt;BR /&gt;@RequestScoped&lt;BR /&gt;public class SimpleStartBean {&lt;BR /&gt;&lt;BR /&gt; @EJB ActivitiServiceEJB activiti;&lt;BR /&gt;&lt;BR /&gt; @EJB TestErpBean testErp;&lt;BR /&gt;&lt;BR /&gt; private String processDefinitionId;&lt;BR /&gt; private String column;&lt;BR /&gt;&lt;BR /&gt; // setters and getters removed…&lt;BR /&gt;&lt;BR /&gt; public String startProcess() throws NamingException, NotSupportedException {&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; TestErpBean testErpBean = (TestErpBean) new InitialContext()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .lookup("java:global/&lt;A href="http://erp.web/TestErpBean" rel="nofollow noopener noreferrer"&gt;erp.web/TestErpBean&lt;/A&gt;");&lt;BR /&gt;&amp;nbsp; TestErp entity = testErpBean.createTestErp();&lt;BR /&gt;&amp;nbsp; entity.setCol(column);&lt;BR /&gt;&amp;nbsp; testErpBean.saveTestErp(entity);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; Map&amp;lt;String, Object&amp;gt; variables = new HashMap&amp;lt;String, Object&amp;gt;();&lt;BR /&gt;&amp;nbsp; variables.put("entity", entity);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; activiti.getProcessEngine().getRuntimeService()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .startProcessInstanceById(processDefinitionId, variables);&lt;BR /&gt;&amp;nbsp; return "owntasklist";&lt;BR /&gt; }&lt;BR /&gt;}&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;TestErp EJB:&lt;/SPAN&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;@Stateless&lt;BR /&gt;@LocalBean&lt;BR /&gt;public class TestErpBean {&lt;BR /&gt; &lt;BR /&gt; @PersistenceUnit(unitName="erp.web")&lt;BR /&gt; EntityManagerFactory emf;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public TestErpBean() {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public TestErp createTestErp() {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EntityManager em = emf.createEntityManager();&lt;BR /&gt;&amp;nbsp; TestErp erp = new TestErp();&lt;BR /&gt;&amp;nbsp; em.persist(erp);&lt;BR /&gt;&amp;nbsp; return erp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void saveTestErp(TestErp testErp) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EntityManager em = emf.createEntityManager();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; em.persist(em.merge(testErp));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public TestErp findTestErp(final int id) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EntityManager em = emf.createEntityManager();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return em.find(TestErp.class, new Integer(id));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;}&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;firstTask:&lt;/SPAN&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;public class FirstTask extends BaseTask implements JavaDelegate {&lt;BR /&gt; @Override&lt;BR /&gt; public void execute(DelegateExecution execution) throws Exception {&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; TestErp entity = (TestErp) execution.getVariable("entity");&lt;BR /&gt;&amp;nbsp; entity.setCol(entity.getCol() + " FIRST");&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; logger.log(Level.FINE, "FirstTask.execute: entity.id = {0} entity.col = {1}", new Object[] {new Integer(entity.getId()), entity.getCol()});&lt;BR /&gt; }&lt;BR /&gt;}&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;secondTask:&lt;/SPAN&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;public class SecondTask extends BaseTask implements JavaDelegate {&lt;BR /&gt; @Override&lt;BR /&gt; public void execute(DelegateExecution execution) throws Exception {&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; TestErp entity = (TestErp) execution.getVariable("entity");&lt;BR /&gt;&amp;nbsp; entity.setCol(entity.getCol()+ " SECOND");&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; logger.log(Level.FINE, "SecondTask.execute: entity.id = {0} entity.col = {1}", new Object[] {new Integer(entity.getId()), entity.getCol()});&lt;BR /&gt; }&lt;BR /&gt;}&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;In the log i see that the field col of the entity is set to "xxx FIRST" and then &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"xxx FIRST SECOND", but when i read the process variable after the second service&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;task from an managed bean and display the value i only get "xxx", which is persisted&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;in the database too. And "while" Activiti executes the first and second service task&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;after starting the process instance (SimpleStartBean.startProcess()) the "owntasklist"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;should be displayed, which results in the following exception when the &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TaskList.getOwnTasks() managed bean method is executed to get the task list from the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ActivitiServiceEJB.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;java.lang.NullPointerException&lt;BR /&gt; at com.sun.enterprise.resource.ConnectorXAResource.getResourceHandle(ConnectorXAResource.java:246)&lt;BR /&gt; at com.sun.enterprise.resource.ConnectorXAResource.start(ConnectorXAResource.java:136)&lt;BR /&gt; at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.enlistResource(JavaEETransactionManagerSimplified.java:375)&lt;BR /&gt; at com.sun.enterprise.resource.rm.ResourceManagerImpl.registerResource(ResourceManagerImpl.java:152)&lt;BR /&gt; at com.sun.enterprise.resource.rm.ResourceManagerImpl.enlistResource(ResourceManagerImpl.java:112)&lt;BR /&gt; at com.sun.enterprise.resource.pool.PoolManagerImpl.getResource(PoolManagerImpl.java:208)&lt;BR /&gt; at com.sun.enterprise.connectors.ConnectionManagerImpl.getResource(ConnectionManagerImpl.java:338)&lt;BR /&gt; at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:301)&lt;BR /&gt; at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:190)&lt;BR /&gt; at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:165)&lt;BR /&gt; at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:160)&lt;BR /&gt; at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:113)&lt;BR /&gt; at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:72)&lt;BR /&gt; at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSession(DefaultSqlSessionFactory.java:32)&lt;BR /&gt; at org.activiti.engine.impl.db.DbSqlSession.&amp;lt;init&amp;gt;(DbSqlSession.java:86)&lt;BR /&gt; at org.activiti.engine.impl.db.DbSqlSessionFactory.openSession(DbSqlSessionFactory.java:77)&lt;BR /&gt; at org.activiti.engine.impl.interceptor.CommandContext.getSession(CommandContext.java:177)&lt;BR /&gt; at org.activiti.engine.impl.cfg.standalone.StandaloneMybatisTransactionContext.getDbSqlSession(StandaloneMybatisTransactionContext.java:77)&lt;BR /&gt; at org.activiti.engine.impl.cfg.standalone.StandaloneMybatisTransactionContext.rollback(StandaloneMybatisTransactionContext.java:91)&lt;BR /&gt; at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:120)&lt;BR /&gt; at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:49)&lt;BR /&gt; at org.activiti.engine.impl.interceptor.JtaTransactionInterceptor.execute(JtaTransactionInterceptor.java:59)&lt;BR /&gt; at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)&lt;BR /&gt; at org.activiti.engine.impl.AbstractQuery.list(AbstractQuery.java:112)&lt;BR /&gt; at erp.web.faces.beans.activiti.TaskList.getOwnTasks(TaskList.java:62)&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;ActivitiServiceEJB:&lt;/SPAN&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;@Singleton&lt;BR /&gt;@LocalBean&lt;BR /&gt;@Startup&lt;BR /&gt;public class ActivitiServiceEJB {&lt;BR /&gt; &lt;BR /&gt; /** the reference to the application wide Activiti process engine. */&lt;BR /&gt; ProcessEngine processEngine = null;&lt;BR /&gt; &lt;BR /&gt; private static Logger logger = Logger.getLogger(ActivitiServiceEJB.class.getName());&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public ActivitiServiceEJB() {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @PostConstruct&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void initEngine() {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProcessEngines.init();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; setProcessEngine(ProcessEngines.getDefaultProcessEngine());&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; logger.log(Level.INFO, "Process engine {0} created and initialized.", getProcessEngine());&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; createActivitiUserData();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @PreRemove&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void destructEngines() {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProcessEngines.destroy();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; logger.log(Level.INFO, "Process engines destroyed.");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&lt;BR /&gt; public ProcessEngine getProcessEngine() {&lt;BR /&gt;&amp;nbsp; return processEngine;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; public void setProcessEngine(ProcessEngine processEngine) {&lt;BR /&gt;&amp;nbsp; this.processEngine = processEngine;&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // removed createActivitiUserData() …&lt;BR /&gt;}&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;TaskList bean:&lt;/SPAN&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;@ManagedBean&lt;BR /&gt;@RequestScoped&lt;BR /&gt;public class TaskList {&lt;BR /&gt;&lt;BR /&gt; @EJB&lt;BR /&gt; ActivitiServiceEJB activiti;&lt;BR /&gt;&lt;BR /&gt; @ManagedProperty(value = "#{userSession}")&lt;BR /&gt; UserSession userSession;&lt;BR /&gt;&lt;BR /&gt; public UserSession getUserSession() {&lt;BR /&gt;&amp;nbsp; return userSession;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; public void setUserSession(UserSession userSession) {&lt;BR /&gt;&amp;nbsp; this.userSession = userSession;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; public List&amp;lt;Task&amp;gt; getOwnTasks() {&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; List&amp;lt;Task&amp;gt; tasks = null;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; if (userSession.isAdmin()) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; tasks = activiti.getProcessEngine().getTaskService()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .createTaskQuery().orderByTaskCreateTime().asc().list();&lt;BR /&gt;&amp;nbsp; } else {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; tasks = activiti.getProcessEngine().getTaskService()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .createTaskQuery()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .taskAssignee(userSession.getUser().getUsername())&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .orderByTaskCreateTime().asc().list();&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; return tasks;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; public String getFormKey(String taskId) {&lt;BR /&gt;&amp;nbsp; String formKey = activiti.getProcessEngine().getFormService()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .getTaskFormData(taskId).getFormKey();&lt;BR /&gt;&amp;nbsp; return formKey;&lt;BR /&gt; }&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;So, this is almost the complete test application and i hope i am not too specific &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://connect.hyland.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope it clarifys what code leeds to the mess i have with the transactions. I &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;tried a lot of different cfg and code snippets, and i am too confused already to&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;see an possibility to get the thing working right &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://connect.hyland.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Chris&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 20 Aug 2011 08:06:11 GMT</pubDate>
    <dc:creator>chris_joelly</dc:creator>
    <dc:date>2011-08-20T08:06:11Z</dc:date>
    <item>
      <title>Create JPA entity in service task</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/create-jpa-entity-in-service-task/m-p/64093#M40353</link>
      <description>Hello,is it possible to create an entity using JPA within an service task and store it asprocess variable and use it in other service tasks? I have instantiated a @Entity in an service task and stored it as process variable. The second service taskthen is not able to retrieve that entity, nor is the</description>
      <pubDate>Fri, 19 Aug 2011 19:19:52 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/create-jpa-entity-in-service-task/m-p/64093#M40353</guid>
      <dc:creator>chris_joelly</dc:creator>
      <dc:date>2011-08-19T19:19:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create JPA entity in service task</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/create-jpa-entity-in-service-task/m-p/64094#M40354</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;if the creation and retrieval are not done in exactly the same entity manager, it is only 'visible' after a commit. Creating it in an ejb remotely could cause it to not be created in the same entity manager. This could also be the case if the creation is done in a timer event etc… So for us to help you, you have to be more specific on what you do.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Aug 2011 21:10:16 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/create-jpa-entity-in-service-task/m-p/64094#M40354</guid>
      <dc:creator>ronald_van_kuij</dc:creator>
      <dc:date>2011-08-19T21:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create JPA entity in service task</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/create-jpa-entity-in-service-task/m-p/64095#M40355</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok, thanks for your time. Here is a short description of my app environment:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Activiti is booted using a singleton EJB which i can inject via @EJB to the &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;managed JSF beans and the app uses JTA with a MySQL datasource. For Activiti the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;datasource and the transaction manager are lookup up via JNDI and configured &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;using JtaProcessEngineConfiguration.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To be honest, i think i mixed up things on transaction handling a lot. I started&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;off with a small JSF webapp to display the deployed process definitions, upload&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and deploy new process definitions, start new process instances and examine the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;task list for the logged in user and the groups he is a member of. The formKey&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;of the startTask and userTasks are used to specify the corresponding JSF form&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;which uses @ManagedBean or @Named beans, and the serviceTask uses normal Java&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;classes for some business logic. The startForms managed bean sets the form&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fields to process variables and then starts a process instance.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Without persistence other then using simple Java objects as process variables &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;everything works fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then i tried to create a JPA entity in the first serviceTask just to see if it&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;is possible to work with JPA persistence within serviceTasks and stored it as&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;process variable as well. The JPA entity i created with an statelss EJB which i &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;looked up via JNDI as well, because i did not find another possibility to get to &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;an persistemce contest within an serviceTask (JavaDelegate). I thought this might&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;be a reaonable use case because this way i can place business logic in reusable &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;session beans. From the next serviceTask in the execution chain i tried to modify&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;the process variable and investigate its modification in the database, because i &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;assumed that Activiti might update this JPA process variable, not only in the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;store for its process variables but in the entities database table as well. But&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;unfortunately this is not the case. When i reload this entity using the stateless&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;session bean then i can only read the initial created entity bean.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then i tried to create the JPA entity from the JSF managed bean already with data&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from the JSF form and set it as process variable when i start off the process &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;instance (opposite to creating the entity from within the first serviceTask).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But too it is not possible to read the entity between the serviceTasks from the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;process variable and the session bean so it reflects the same value. From the &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;stack trace i saw during my debugging sessions i have the impression that a &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;process instance is executed the whole execution path all the way through till&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;the process instance arrives at a wait state? E.g. a userTask? Is this the moment&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;the process variables are persisted to the database? And is this the moment a &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;transaction in the Activiti world ends? At least i think so, but i dont know it&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;yet.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, i think my problem is that i am not able to integrate transaction handling&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;between the stateless session bean and Activiti. I thought JTA on Activiti's &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and the EJB's side will do the trick, but i am not sure if i am using it the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;right way. I dont know too if i need to configure Activiti in a way, besides the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;datasource and the transaction manager, so it is aware of the JPA persistence&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;unit to be able to handle JPA process variables.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;activiti.cfg.xml:&lt;/SPAN&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt; &amp;lt;jee:jndi-lookup jndi-name="jdbc/MysqlErp" id="dataSource" /&amp;gt;&lt;BR /&gt; &amp;lt;jee:jndi-lookup jndi-name="java:appserver/TransactionManager" id="transactionManager" /&amp;gt;&lt;BR /&gt; &amp;lt;bean id="processEngineConfiguration"&lt;BR /&gt;&amp;nbsp; class="org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration"&amp;gt;&lt;BR /&gt;&amp;nbsp; &amp;lt;property name="dataSource" ref="dataSource" /&amp;gt;&lt;BR /&gt;&amp;nbsp; &amp;lt;property name="transactionManager" ref="transactionManager"/&amp;gt;&lt;BR /&gt;&amp;nbsp; &amp;lt;property name="transactionsExternallyManaged" value="true" /&amp;gt;&lt;BR /&gt;&amp;nbsp; &amp;lt;property name="databaseSchemaUpdate" value="true" /&amp;gt;&lt;BR /&gt;&amp;nbsp; &amp;lt;property name="databaseType" value="mysql" /&amp;gt;&lt;BR /&gt;&amp;nbsp; &amp;lt;property name="jobExecutorActivate" value="false" /&amp;gt;&lt;BR /&gt; &amp;lt;/bean&amp;gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;StartBean:&lt;/SPAN&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;@Named&lt;BR /&gt;@RequestScoped&lt;BR /&gt;public class SimpleStartBean {&lt;BR /&gt;&lt;BR /&gt; @EJB ActivitiServiceEJB activiti;&lt;BR /&gt;&lt;BR /&gt; @EJB TestErpBean testErp;&lt;BR /&gt;&lt;BR /&gt; private String processDefinitionId;&lt;BR /&gt; private String column;&lt;BR /&gt;&lt;BR /&gt; // setters and getters removed…&lt;BR /&gt;&lt;BR /&gt; public String startProcess() throws NamingException, NotSupportedException {&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; TestErpBean testErpBean = (TestErpBean) new InitialContext()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .lookup("java:global/&lt;A href="http://erp.web/TestErpBean" rel="nofollow noopener noreferrer"&gt;erp.web/TestErpBean&lt;/A&gt;");&lt;BR /&gt;&amp;nbsp; TestErp entity = testErpBean.createTestErp();&lt;BR /&gt;&amp;nbsp; entity.setCol(column);&lt;BR /&gt;&amp;nbsp; testErpBean.saveTestErp(entity);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; Map&amp;lt;String, Object&amp;gt; variables = new HashMap&amp;lt;String, Object&amp;gt;();&lt;BR /&gt;&amp;nbsp; variables.put("entity", entity);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; activiti.getProcessEngine().getRuntimeService()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .startProcessInstanceById(processDefinitionId, variables);&lt;BR /&gt;&amp;nbsp; return "owntasklist";&lt;BR /&gt; }&lt;BR /&gt;}&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;TestErp EJB:&lt;/SPAN&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;@Stateless&lt;BR /&gt;@LocalBean&lt;BR /&gt;public class TestErpBean {&lt;BR /&gt; &lt;BR /&gt; @PersistenceUnit(unitName="erp.web")&lt;BR /&gt; EntityManagerFactory emf;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public TestErpBean() {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public TestErp createTestErp() {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EntityManager em = emf.createEntityManager();&lt;BR /&gt;&amp;nbsp; TestErp erp = new TestErp();&lt;BR /&gt;&amp;nbsp; em.persist(erp);&lt;BR /&gt;&amp;nbsp; return erp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void saveTestErp(TestErp testErp) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EntityManager em = emf.createEntityManager();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; em.persist(em.merge(testErp));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public TestErp findTestErp(final int id) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EntityManager em = emf.createEntityManager();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return em.find(TestErp.class, new Integer(id));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;}&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;firstTask:&lt;/SPAN&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;public class FirstTask extends BaseTask implements JavaDelegate {&lt;BR /&gt; @Override&lt;BR /&gt; public void execute(DelegateExecution execution) throws Exception {&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; TestErp entity = (TestErp) execution.getVariable("entity");&lt;BR /&gt;&amp;nbsp; entity.setCol(entity.getCol() + " FIRST");&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; logger.log(Level.FINE, "FirstTask.execute: entity.id = {0} entity.col = {1}", new Object[] {new Integer(entity.getId()), entity.getCol()});&lt;BR /&gt; }&lt;BR /&gt;}&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;secondTask:&lt;/SPAN&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;public class SecondTask extends BaseTask implements JavaDelegate {&lt;BR /&gt; @Override&lt;BR /&gt; public void execute(DelegateExecution execution) throws Exception {&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; TestErp entity = (TestErp) execution.getVariable("entity");&lt;BR /&gt;&amp;nbsp; entity.setCol(entity.getCol()+ " SECOND");&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; logger.log(Level.FINE, "SecondTask.execute: entity.id = {0} entity.col = {1}", new Object[] {new Integer(entity.getId()), entity.getCol()});&lt;BR /&gt; }&lt;BR /&gt;}&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;In the log i see that the field col of the entity is set to "xxx FIRST" and then &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"xxx FIRST SECOND", but when i read the process variable after the second service&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;task from an managed bean and display the value i only get "xxx", which is persisted&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;in the database too. And "while" Activiti executes the first and second service task&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;after starting the process instance (SimpleStartBean.startProcess()) the "owntasklist"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;should be displayed, which results in the following exception when the &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TaskList.getOwnTasks() managed bean method is executed to get the task list from the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ActivitiServiceEJB.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;java.lang.NullPointerException&lt;BR /&gt; at com.sun.enterprise.resource.ConnectorXAResource.getResourceHandle(ConnectorXAResource.java:246)&lt;BR /&gt; at com.sun.enterprise.resource.ConnectorXAResource.start(ConnectorXAResource.java:136)&lt;BR /&gt; at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.enlistResource(JavaEETransactionManagerSimplified.java:375)&lt;BR /&gt; at com.sun.enterprise.resource.rm.ResourceManagerImpl.registerResource(ResourceManagerImpl.java:152)&lt;BR /&gt; at com.sun.enterprise.resource.rm.ResourceManagerImpl.enlistResource(ResourceManagerImpl.java:112)&lt;BR /&gt; at com.sun.enterprise.resource.pool.PoolManagerImpl.getResource(PoolManagerImpl.java:208)&lt;BR /&gt; at com.sun.enterprise.connectors.ConnectionManagerImpl.getResource(ConnectionManagerImpl.java:338)&lt;BR /&gt; at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:301)&lt;BR /&gt; at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:190)&lt;BR /&gt; at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:165)&lt;BR /&gt; at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:160)&lt;BR /&gt; at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:113)&lt;BR /&gt; at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:72)&lt;BR /&gt; at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSession(DefaultSqlSessionFactory.java:32)&lt;BR /&gt; at org.activiti.engine.impl.db.DbSqlSession.&amp;lt;init&amp;gt;(DbSqlSession.java:86)&lt;BR /&gt; at org.activiti.engine.impl.db.DbSqlSessionFactory.openSession(DbSqlSessionFactory.java:77)&lt;BR /&gt; at org.activiti.engine.impl.interceptor.CommandContext.getSession(CommandContext.java:177)&lt;BR /&gt; at org.activiti.engine.impl.cfg.standalone.StandaloneMybatisTransactionContext.getDbSqlSession(StandaloneMybatisTransactionContext.java:77)&lt;BR /&gt; at org.activiti.engine.impl.cfg.standalone.StandaloneMybatisTransactionContext.rollback(StandaloneMybatisTransactionContext.java:91)&lt;BR /&gt; at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:120)&lt;BR /&gt; at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:49)&lt;BR /&gt; at org.activiti.engine.impl.interceptor.JtaTransactionInterceptor.execute(JtaTransactionInterceptor.java:59)&lt;BR /&gt; at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)&lt;BR /&gt; at org.activiti.engine.impl.AbstractQuery.list(AbstractQuery.java:112)&lt;BR /&gt; at erp.web.faces.beans.activiti.TaskList.getOwnTasks(TaskList.java:62)&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;ActivitiServiceEJB:&lt;/SPAN&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;@Singleton&lt;BR /&gt;@LocalBean&lt;BR /&gt;@Startup&lt;BR /&gt;public class ActivitiServiceEJB {&lt;BR /&gt; &lt;BR /&gt; /** the reference to the application wide Activiti process engine. */&lt;BR /&gt; ProcessEngine processEngine = null;&lt;BR /&gt; &lt;BR /&gt; private static Logger logger = Logger.getLogger(ActivitiServiceEJB.class.getName());&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public ActivitiServiceEJB() {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @PostConstruct&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void initEngine() {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProcessEngines.init();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; setProcessEngine(ProcessEngines.getDefaultProcessEngine());&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; logger.log(Level.INFO, "Process engine {0} created and initialized.", getProcessEngine());&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; createActivitiUserData();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @PreRemove&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void destructEngines() {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProcessEngines.destroy();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; logger.log(Level.INFO, "Process engines destroyed.");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&lt;BR /&gt; public ProcessEngine getProcessEngine() {&lt;BR /&gt;&amp;nbsp; return processEngine;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; public void setProcessEngine(ProcessEngine processEngine) {&lt;BR /&gt;&amp;nbsp; this.processEngine = processEngine;&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // removed createActivitiUserData() …&lt;BR /&gt;}&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;TaskList bean:&lt;/SPAN&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;@ManagedBean&lt;BR /&gt;@RequestScoped&lt;BR /&gt;public class TaskList {&lt;BR /&gt;&lt;BR /&gt; @EJB&lt;BR /&gt; ActivitiServiceEJB activiti;&lt;BR /&gt;&lt;BR /&gt; @ManagedProperty(value = "#{userSession}")&lt;BR /&gt; UserSession userSession;&lt;BR /&gt;&lt;BR /&gt; public UserSession getUserSession() {&lt;BR /&gt;&amp;nbsp; return userSession;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; public void setUserSession(UserSession userSession) {&lt;BR /&gt;&amp;nbsp; this.userSession = userSession;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; public List&amp;lt;Task&amp;gt; getOwnTasks() {&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; List&amp;lt;Task&amp;gt; tasks = null;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; if (userSession.isAdmin()) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; tasks = activiti.getProcessEngine().getTaskService()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .createTaskQuery().orderByTaskCreateTime().asc().list();&lt;BR /&gt;&amp;nbsp; } else {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; tasks = activiti.getProcessEngine().getTaskService()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .createTaskQuery()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .taskAssignee(userSession.getUser().getUsername())&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .orderByTaskCreateTime().asc().list();&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; return tasks;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; public String getFormKey(String taskId) {&lt;BR /&gt;&amp;nbsp; String formKey = activiti.getProcessEngine().getFormService()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .getTaskFormData(taskId).getFormKey();&lt;BR /&gt;&amp;nbsp; return formKey;&lt;BR /&gt; }&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;So, this is almost the complete test application and i hope i am not too specific &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://connect.hyland.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope it clarifys what code leeds to the mess i have with the transactions. I &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;tried a lot of different cfg and code snippets, and i am too confused already to&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;see an possibility to get the thing working right &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://connect.hyland.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Chris&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Aug 2011 08:06:11 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/create-jpa-entity-in-service-task/m-p/64095#M40355</guid>
      <dc:creator>chris_joelly</dc:creator>
      <dc:date>2011-08-20T08:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: Create JPA entity in service task</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/create-jpa-entity-in-service-task/m-p/64096#M40356</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;From the &lt;BR /&gt;stack trace i saw during my debugging sessions i have the impression that a &lt;BR /&gt;process instance is executed the whole execution path all the way through till&lt;BR /&gt;the process instance arrives at a wait state? E.g. a userTask? Is this the moment&lt;BR /&gt;the process variables are persisted to the database? And is this the moment a &lt;BR /&gt;transaction in the Activiti world ends? At least i think so, but i dont know it&lt;BR /&gt;yet.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;Will go into other things later, but this assumption is correct.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I you want persistence in between, vote for &lt;/SPAN&gt;&lt;A href="http://jira.codehaus.org/browse/ACT-126" rel="nofollow noopener noreferrer"&gt;http://jira.codehaus.org/browse/ACT-126&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Aug 2011 09:58:11 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/create-jpa-entity-in-service-task/m-p/64096#M40356</guid>
      <dc:creator>ronald_van_kuij</dc:creator>
      <dc:date>2011-08-20T09:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: Create JPA entity in service task</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/create-jpa-entity-in-service-task/m-p/64097#M40357</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Ronald,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;did u have the time to look into that issue?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Chris&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Aug 2011 18:13:58 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/create-jpa-entity-in-service-task/m-p/64097#M40357</guid>
      <dc:creator>chris_joelly</dc:creator>
      <dc:date>2011-08-31T18:13:58Z</dc:date>
    </item>
  </channel>
</rss>

