<?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: Troubles with JPA / Activiti CDI initialisation in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/troubles-with-jpa-activiti-cdi-initialisation/m-p/99470#M68777</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;it seems that i found the reason why i can not inject a EntityManagerFactory which is looked up using JNDI using activiti.cfg.xml when Activiti is initialized. I use activiti-cdi to "boot" the process engine and during that phase Activiti is initialized using the Spring style config mechanism. In that mechanism i used &amp;lt;jee:jndi-lookup…/&amp;gt; to get an EMF and inject it to Activiti so that Activiti is able to use the same persistence unit which is used throughout the rest of the app. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But when Activiti is initialized by the WeldDeployer there is no java:comp/env JNDI name space available, so it is not possible to use the JNDI component environment during that phase. And, furthermore, if i postpone the JNDI lookup with &amp;lt;jee:jndi-lookup… lookup-on-startup="false" proxy-interface="javax.persistence.EntityManagerFactory"/&amp;gt; so that the complete webapp is initialized first before Activiti tries to access the EMF then the JNDI lookup to java:comp/env does not work either, Activiti does not see this JNDI context. And when Activiti executes a timer event, java:comp/env is not available too.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, when activiti-cdi is used, only global JNDI resources can be used, as it works with a datasource for example which can be found at jdbc:… and not below java:comp/env…. The component environment, e.g. via a persistence-unit-ref in web.xml, is not usable with activiti-cdi. At least i dont know how to do it &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;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 09 Jun 2012 09:24:50 GMT</pubDate>
    <dc:creator>chris_joelly</dc:creator>
    <dc:date>2012-06-09T09:24:50Z</dc:date>
    <item>
      <title>Troubles with JPA / Activiti CDI initialisation</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/troubles-with-jpa-activiti-cdi-initialisation/m-p/99467#M68774</link>
      <description>Hello,i am not sure if this is the right forum for my problem, but as it only happensin the context of an Activiti execution i decided to post it here.I run into troubles when i change a property on an JPA process variable from withinan service task. The owning entity is an Order having a ManyToOne</description>
      <pubDate>Sun, 27 May 2012 20:14:18 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/troubles-with-jpa-activiti-cdi-initialisation/m-p/99467#M68774</guid>
      <dc:creator>chris_joelly</dc:creator>
      <dc:date>2012-05-27T20:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: Troubles with JPA / Activiti CDI initialisation</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/troubles-with-jpa-activiti-cdi-initialisation/m-p/99468#M68775</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When using JPA inside Activiti there are two ways of wiring in the EntityManager (&lt;/SPAN&gt;&lt;A href="http://activiti.org/userguide/index.html#jpaconfiguration" rel="nofollow noopener noreferrer"&gt;http://activiti.org/userguide/index.html#jpaconfiguration&lt;/A&gt;&lt;SPAN&gt;). The fist on is using the persistence-unit name. If this value is set,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;interceptors are added to the stack, which flush the entity manager every time an activity operation ends (e.g.. startProcess, completeTask). The entity manager is obtained using the default way, using the persistence-unit name (EntityManagerFactory).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Another option is to pass in a reference to your (potentially managed) EntityManagerFactory, instead of the PU-name. This way, not a default EntityManager will be used, but one that is aware of your environment/app.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd recommend using the second approach, wiring in your entityManagerFactory. Make sure, in case the entityManager is "managed", you set the "jpaCloseEntityManager" and "jpaHandleTransaction" properties to false. In that case, the closing/comitting will be done by your services wrapping activiti-calls, rather than in activiti-calls itself.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 May 2012 12:14:25 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/troubles-with-jpa-activiti-cdi-initialisation/m-p/99468#M68775</guid>
      <dc:creator>frederikherema1</dc:creator>
      <dc:date>2012-05-29T12:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Troubles with JPA / Activiti CDI initialisation</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/troubles-with-jpa-activiti-cdi-initialisation/m-p/99469#M68776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thank u for your answer. As u saw in my activiti.cfg.xml i used the first option, setting the JPA persistence unit name. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried to change to the second approach, and defined the persistence-unit-ref in the web.xml so i can access it via JNDI. I can access it via java:comp/env, this works fine when i perform the lookup from within an EJB. At the moment the EMF is injected into Activiti i can not access the name space java:comp/env and so i can not wire in the EntityManagerFactory.&lt;/SPAN&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;&amp;lt;jee:jndi-lookup id="entityManagerFactory" jndi-name="java:comp/env/persistence/erpEMF" lookup-on-startup="false" proxy-interface="javax.persistence.EntityManagerFactory"/&amp;gt;&lt;BR /&gt;…&lt;BR /&gt;&amp;lt;bean id="processEngineConfiguration"&lt;BR /&gt; class="org.activiti.cdi.CdiJtaProcessEngineConfiguration"&amp;gt;&lt;BR /&gt; &amp;lt;property name="jpaEntityManagerFactory" ref="entityManagerFactory" /&amp;gt;&lt;BR /&gt;…&lt;BR /&gt;&lt;/CODE&gt;&lt;SPAN&gt;does not work from the Spring based Activiti initialisation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I never used Spring before (Activiti) and so i am relatively new to the Spring world. I implemented a proxy for the EntityManagerFactory which pulls one from JNDI if the proxy methods are accessed, and there i saw that in this execution context i can not access java:comp/env.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;&amp;lt;bean id="entityManagerFactory" class="erp.domain.activiti.mgnt.EMFProxy"&amp;gt;&lt;BR /&gt; &amp;lt;property name="jndiName" value="java:comp/env/persistence/erpEMF" /&amp;gt;&lt;BR /&gt;&amp;lt;/bean&amp;gt;&lt;BR /&gt;…&lt;BR /&gt;&amp;lt;bean id="processEngineConfiguration"&lt;BR /&gt; class="org.activiti.cdi.CdiJtaProcessEngineConfiguration"&amp;gt;&lt;BR /&gt; &amp;lt;property name="jpaEntityManagerFactory" ref="entityManagerFactory" /&amp;gt;&lt;BR /&gt;…&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;FEIN: Start with context: 'java:comp/env'&lt;BR /&gt;SCHWERWIEGEND: Error dumping JNDI tree&lt;BR /&gt;javax.naming.NamingException: Lookup failed for 'java:comp/env' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Invocation exception: Got null ComponentInvocation ]&lt;BR /&gt; at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)&lt;BR /&gt; at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)&lt;BR /&gt; at javax.naming.InitialContext.lookup(InitialContext.java:392)&lt;BR /&gt; at javax.naming.InitialContext.lookup(InitialContext.java:392)&lt;BR /&gt; at erp.domain.activiti.mgnt.JNDITreeDumper.dumpJndiTree(JNDITreeDumper.java:33)&lt;BR /&gt; at erp.domain.activiti.mgnt.EMFProxy.initialiseEMF(EMFProxy.java:104)&lt;BR /&gt; at erp.domain.activiti.mgnt.EMFProxy.createEntityManager(EMFProxy.java:44)&lt;BR /&gt; at org.activiti.engine.impl.variable.EntityManagerSessionImpl.getEntityManager(EntityManagerSessionImpl.java:84)&lt;BR /&gt; at org.activiti.engine.impl.variable.JPAEntityMappings.findEntity(JPAEntityMappings.java:123)&lt;BR /&gt; at org.activiti.engine.impl.variable.JPAEntityMappings.getJPAEntity(JPAEntityMappings.java:119)&lt;BR /&gt; at org.activiti.engine.impl.variable.JPAEntityVariableType.getValue(JPAEntityVariableType.java:77)&lt;BR /&gt; at org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.getValue(VariableInstanceEntity.java:158)&lt;BR /&gt; at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.getVariable(VariableScopeImpl.java:93)&lt;BR /&gt; at org.activiti.engine.impl.bpmn.behavior.CallActivityBehavior.execute(CallActivityBehavior.java:79)&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;To verify this behavior i wrote an JNDI tree dumper which i use from a @Singleton @Startup EJB and from the EMF proxy. When it is accessed in the context of the EMF proxy when Activiti tries to get an EntityManager from the EMF proxy i can not access the JNDI name space java:comp/env, thus i can not access the provided EMF from the application server.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried in two app servers, Glassfish 3.1.2 and JBoss AS 7.1.1, both show me the same behavior.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I dont know how i can wire in the EntityManagerFactory from my app server using Spring, it seems there is something wrong with my concept of the app architecture. I read lots of spec docs last days but it seems java:comp/env resources are not meant to be visible in a context outside an JEE module, but i dont understand why the Spring based Activiti initialization phase happens outside the webapp/war context. And i tried to get the EMF to the "global" context just like the data source which can be looked up via JNDI, but this seem to be not possible soley through deployment descriptors.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyway, after all this mess i will finish my day with lots of beer &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 anyway,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Chris&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 03 Jun 2012 18:56:00 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/troubles-with-jpa-activiti-cdi-initialisation/m-p/99469#M68776</guid>
      <dc:creator>chris_joelly</dc:creator>
      <dc:date>2012-06-03T18:56:00Z</dc:date>
    </item>
    <item>
      <title>Re: Troubles with JPA / Activiti CDI initialisation</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/troubles-with-jpa-activiti-cdi-initialisation/m-p/99470#M68777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;it seems that i found the reason why i can not inject a EntityManagerFactory which is looked up using JNDI using activiti.cfg.xml when Activiti is initialized. I use activiti-cdi to "boot" the process engine and during that phase Activiti is initialized using the Spring style config mechanism. In that mechanism i used &amp;lt;jee:jndi-lookup…/&amp;gt; to get an EMF and inject it to Activiti so that Activiti is able to use the same persistence unit which is used throughout the rest of the app. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But when Activiti is initialized by the WeldDeployer there is no java:comp/env JNDI name space available, so it is not possible to use the JNDI component environment during that phase. And, furthermore, if i postpone the JNDI lookup with &amp;lt;jee:jndi-lookup… lookup-on-startup="false" proxy-interface="javax.persistence.EntityManagerFactory"/&amp;gt; so that the complete webapp is initialized first before Activiti tries to access the EMF then the JNDI lookup to java:comp/env does not work either, Activiti does not see this JNDI context. And when Activiti executes a timer event, java:comp/env is not available too.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, when activiti-cdi is used, only global JNDI resources can be used, as it works with a datasource for example which can be found at jdbc:… and not below java:comp/env…. The component environment, e.g. via a persistence-unit-ref in web.xml, is not usable with activiti-cdi. At least i dont know how to do it &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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Jun 2012 09:24:50 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/troubles-with-jpa-activiti-cdi-initialisation/m-p/99470#M68777</guid>
      <dc:creator>chris_joelly</dc:creator>
      <dc:date>2012-06-09T09:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: Troubles with JPA / Activiti CDI initialisation</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/troubles-with-jpa-activiti-cdi-initialisation/m-p/99471#M68778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It seems I've fallen into the same trap. After few hours of experiment the following helped:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;upgrade EclipseLink from 2.3.3 -&amp;gt; 2.4.1&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It is "green" and not tested remedium. I am just happy to share it with you! I never upgraded underlying EL so I cannt figure all the side effects. I will share more results after testings.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Feb 2013 13:05:44 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/troubles-with-jpa-activiti-cdi-initialisation/m-p/99471#M68778</guid>
      <dc:creator>p4w3l</dc:creator>
      <dc:date>2013-02-08T13:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: Troubles with JPA / Activiti CDI initialisation</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/troubles-with-jpa-activiti-cdi-initialisation/m-p/99472#M68779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The reason I post here is that I see some similarities with initial post:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- EclipseLink 2.3.3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- production quality set of JPA libraries that works fine just with one exception:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When my CDI @BusinessProcess @Observes @EndActivity tries to modify JPA process attached entity - the flush exception is raised. It happens in the following conditions:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- the whole CDI method is succesfully executed ( JPA data change is commited )&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- the flush exception is in taskService.complete(…) after CDI method is done&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- the related entity must be modified. Modifing only scalar values of JPA variable doesn't raise the flush exception.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Simply upgrade from EclipseLink 2.3.3 to 2.4.1 solves the problem.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Feb 2013 12:22:08 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/troubles-with-jpa-activiti-cdi-initialisation/m-p/99472#M68779</guid>
      <dc:creator>p4w3l</dc:creator>
      <dc:date>2013-02-10T12:22:08Z</dc:date>
    </item>
  </channel>
</rss>

