10 Replies Latest reply on Jan 25, 2012 4:43 AM by Lucas Ventura Carro

    Transactional and EntityManager with Seam-Persistence+Weld+EclipseLink+Tomcat

    Leonardo Costa Newbie

      I'm having problems on entityManager access with seam-persistence, weld, eclipselink and tomcat. Everything seems to go perfectly:


      Logs:



      INFO: WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
      30/09/2011 08:48:47 org.jboss.seam.solder.core.VersionLoggerUtil logVersionInformation
      INFO: Seam Solder 3.0.0.Final (build id: 3.0.0.Final)
      INFO: Configuring Seam Managed Persistence Context from producer field pacote.library.PersistenceProducer.emf with qualifiers (@javax.enterprise.inject.Any(),
      @javax.enterprise.inject.Default())


      Error exception:



      Caused by: javax.naming.NamingException - Cannot create resource instance at org.apache.naming.factory.TransactionFactory.getObjectInstance(TransactionFactory.java:116)



      My implementation:



      My beans.xml


      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:s="urn:java:ee"
           xmlns:t="urn:java:org.jboss.seam.transaction"
           xmlns:ft="urn:java:org.jboss.seam.faces.transaction"
           xmlns:sc="urn:java:org.jboss.seam.solder.core"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd">
      
           <interceptors>
                <class>org.jboss.seam.transaction.TransactionInterceptor</class>
           </interceptors>
      
            <t:SeSynchronizations>
                <s:modifies />
           </t:SeSynchronizations>
           <t:EntityTransaction>
                <s:modifies />
           </t:EntityTransaction>
      
      </beans>
      




      My producer:


      public class PersistenceProducer {
        @Produces
        @ConversationScoped
        @ExtensionManaged
        @PersistenceUnit(unitName = "TemplateRichFacesPU")
        EntityManagerFactory emf;
      }
      




      My generic DAO:


      @Transactional
      public class BaseDaoImp<T, ID> implements BaseDaoInt<T, ID>, Serializable {
        private static final long serialVersionUID = -1L;
      
        @Inject
        private EntityManager entityManager;
      
        @Transactional
        public List<T> getAll() {
          Query qry = entityManager.createNamedQuery("table.all");
          return (List<T>) qry.getResultList();
        }
      }
      



      My extent:


      @Named
      @Dependent
      public class AutorDao extends BaseDaoImp<Autor, Long> {
        private static final long serialVersionUID = -1L;
      
        public List todosAutores() {
          List<Autor> result = getAll();
          return result;
        }
      }
      





      Use:


      @Named
      @ConversationScoped
      public class AdminAutorCtrl implements Serializable {
        private static final long serialVersionUID = -1L;
      
        @Inject
        private AutorDao autorDao;
      
        private Autor[] autores;
      
        public void todosAutores() {
          autores = (Autor[]) autorDao.getAll().toArray(new Autor[0]);
       }
      }
      




      Error exception:


      org.apache.myfaces.view.facelets.el.ContextAwareELException: javax.el.ELException: Error reading 'autor' on type pacote.controller.AdminAutorCtrl$Proxy$_$$_WeldClientProxy
           at org.apache.myfaces.view.facelets.el.TagValueExpression.getValue(TagValueExpression.java:101)
           at javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:246)
           at javax.faces.component.UIOutput.getValue(UIOutput.java:71)
           at javax.faces.component.UIInput.getValue(UIInput.java:147)
           at org.apache.myfaces.shared.renderkit.RendererUtils.getValue(RendererUtils.java:347)
           at org.apache.myfaces.shared.renderkit.RendererUtils.getStringValue(RendererUtils.java:295)
           at org.apache.myfaces.shared.renderkit.html.HtmlTextRendererBase.renderInputBegin(HtmlTextRendererBase.java:190)
           at org.apache.myfaces.shared.renderkit.html.HtmlTextRendererBase.renderInput(HtmlTextRendererBase.java:179)
           at org.apache.myfaces.shared.renderkit.html.HtmlTextRendererBase.encodeEnd(HtmlTextRendererBase.java:75)
           at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:539)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:685)
           at org.apache.myfaces.shared.renderkit.html.HtmlGridRendererBase.renderChildren(HtmlGridRendererBase.java:336)
           at org.apache.myfaces.shared.renderkit.html.HtmlGridRendererBase.encodeEnd(HtmlGridRendererBase.java:169)
           at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:539)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:685)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:681)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:681)
           at org.richfaces.renderkit.RendererBase.renderChildren(RendererBase.java:276)
           at org.richfaces.renderkit.html.PanelRenderer.encodeEnd(PanelRenderer.java:181)
           at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:539)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:685)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:681)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:681)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:681)
           at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1695)
           at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:281)
           at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:59)
           at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:59)
           at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:90)
           at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:239)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:185)
           at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:151)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
           at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:269)
           at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
           at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
           at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
           at java.lang.Thread.run(Unknown Source)
      Caused by: javax.el.ELException: Error reading 'autor' on type pacote.controller.AdminAutorCtrl$Proxy$_$$_WeldClientProxy
           at javax.el.BeanELResolver.getValue(BeanELResolver.java:91)
           at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
           at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:171)
           at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
           at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
           at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:55)
           at org.apache.myfaces.view.facelets.el.TagValueExpression.getValue(TagValueExpression.java:93)
           ... 46 more
      Caused by: org.jboss.weld.exceptions.WeldException: WELD-000049 Unable to invoke [method] @PostConstruct public pacote.controller.AdminAutorCtrl.init() on 
      
      pacote.controller.AdminAutorCtrl@16ae29f
           at org.jboss.weld.bean.AbstractClassBean.defaultPostConstruct(AbstractClassBean.java:595)
           at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget.postConstruct(ManagedBean.java:200)
           at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:340)
           at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:122)
           at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:99)
           at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:87)
           at pacote.controller.AdminAutorCtrl$Proxy$_$$_WeldClientProxy.getAutor(AdminAutorCtrl$Proxy$_$$_WeldClientProxy.java)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
           at java.lang.reflect.Method.invoke(Unknown Source)
           at javax.el.BeanELResolver.getValue(BeanELResolver.java:87)
           ... 52 more
      Caused by: java.lang.reflect.InvocationTargetException
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
           at java.lang.reflect.Method.invoke(Unknown Source)
           at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:305)
           at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)
           at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163)
           at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:299)
           at org.jboss.weld.introspector.jlr.WeldMethodImpl.invoke(WeldMethodImpl.java:193)
           at org.jboss.weld.bean.AbstractClassBean.defaultPostConstruct(AbstractClassBean.java:591)
           ... 63 more
      Caused by: java.lang.RuntimeException: javax.naming.NamingException: Cannot create resource instance
           at org.jboss.seam.transaction.DefaultSeamTransaction.getSeamTransaction(DefaultSeamTransaction.java:153)
           at org.jboss.seam.transaction.DefaultSeamTransaction.isActiveOrMarkedRollback(DefaultSeamTransaction.java:62)
           at org.jboss.seam.transaction.Work.workInTransaction(Work.java:42)
           at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:188)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
           at java.lang.reflect.Method.invoke(Unknown Source)
           at org.jboss.interceptor.proxy.InterceptorInvocation$InterceptorMethodInvocation.invoke(InterceptorInvocation.java:72)
           at org.jboss.interceptor.proxy.SimpleInterceptionChain.invokeNextInterceptor(SimpleInterceptionChain.java:82)
           at org.jboss.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:133)
           at org.jboss.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:112)
           at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:65)
           at pacote.dao.-1608738265$Proxy$_$$_WeldSubclass.getAll(-1608738265$Proxy$_$$_WeldSubclass.java)
           at pacote.controller.AdminAutorCtrl.todosAutores(AdminAutorCtrl.java:82)
           at pacote.controller.AdminAutorCtrl.init(AdminAutorCtrl.java:38)
           ... 73 more
      Caused by: javax.naming.NamingException: Cannot create resource instance
           at org.apache.naming.factory.TransactionFactory.getObjectInstance(TransactionFactory.java:116)
           at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
           at org.apache.naming.NamingContext.lookup(NamingContext.java:826)
           at org.apache.naming.NamingContext.lookup(NamingContext.java:145)
           at org.apache.naming.NamingContext.lookup(NamingContext.java:814)
           at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
           at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
           at javax.naming.InitialContext.lookup(Unknown Source)
           at org.jboss.seam.transaction.DefaultSeamTransaction.getUserTransaction(DefaultSeamTransaction.java:177)
           at org.jboss.seam.transaction.DefaultSeamTransaction.createUTTransaction(DefaultSeamTransaction.java:169)
           at org.jboss.seam.transaction.DefaultSeamTransaction.getSeamTransaction(DefaultSeamTransaction.java:134)
           ... 88 more
      


        • 1. Re: Transactional and EntityManager with Seam-Persistence+Weld+EclipseLink+Tomcat
          Jason Porter Master

          Do you have the jta.jar in the classpath, and a JTA implementation? You'll also need to get it all setup correctly in JNDI using tomcat, see their docs for that.

          • 2. Re: Transactional and EntityManager with Seam-Persistence+Weld+EclipseLink+Tomcat
            Leonardo Costa Newbie

            The documentation is very sparse for Tomcat/SE. The research I have done, lead me to confusion. I do not know what exactly to use, and interconnect. Which is correct?


            In persistence.xml:




                <persistence-unit name="TemplateRichFacesPU" transaction-type="RESOURCE_LOCAL">
            
                <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
            
                <jta-data-source>java:comp/env/jdbc/TemplateRichFacesDS</jta-data-source>
                OR
                <non-jta-data-source>java:comp/env/jdbc/TemplateRichFacesDS</non-jta-data-source> 
            





            In Tomcat context.xml



              <Resource
                  name="jdbc/TemplateRichFacesDS"
                  (...)
              />
              <Resource
                 name="UserTransaction"
                 auth="Container"
                 type="javax.transaction.UserTransaction"/>
              <ResourceParams
                 name="UserTransaction">
                <parameter>
                 <name>factory</name>
                 <value>?!? what to use here (EclipseLink) ?!?</value>
                </parameter>    
              </ResourceParams>
            




            In WebContent/WEB-INF/components.xml (?!?!?)




            <?xml version="1.0" encoding="UTF-8"?>
            <component name="org.jboss.seam.persistence.persistenceProvider" 
                 class="org.jboss.seam.persistence.PersistenceProvider"
                 scope="stateless">
            </component>





            OR




            <?xml version="1.0" encoding="UTF-8"?>
            <components xmlns="http://jboss.com/products/seam/components"
                xmlns:core="http://jboss.com/products/seam/core"
                xmlns:persistence="http://jboss.com/products/seam/persistence"
                xmlns:transaction="http://jboss.com/products/seam/transaction"
                xmlns:web="http://jboss.com/products/seam/web"
                xmlns:security="http://jboss.com/products/seam/security"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation=
              "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
                http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
                http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.0.xsd
                http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">
            
              <core:init debug="true" transaction-management-enabled="true" jndi-pattern="jdbc/" />
            
              <persistence:entity-manager-factory name="entityManagerFactory" persistence-unit-name="TemplateRichFacesDS" />
            
              <transaction:entity-transaction entity-manager="#{entityManager}"/>
            
              <persistence:managed-persistence-context auto-create="true" name="entityManager"
                entity-manager-factory="#{entityManagerFactory}"/>
            
            </components>
            




            Is not there someone here who has a way (howto/manual), an example, a link?
            (That is worthy of understanding, complete, close the circle...)






            • 3. Re: Transactional and EntityManager with Seam-Persistence+Weld+EclipseLink+Tomcat
              Jason Porter Master

              If you're using Seam 3, there is no components.xml. For the other stuff, sorry, I can't help. I'm not a tomcat guy, never have been.

              • 4. Re: Transactional and EntityManager with Seam-Persistence+Weld+EclipseLink+Tomcat
                Leonardo Costa Newbie

                I've suspected that the use of components.xml was deprecated. But I still insist on using seam-persistence in Tomcat. Even the Docs say is possible. Excuse my insistence. I never was trying was not the docs say it is possible.


                - You as a person of the development team, do not advise opening bug track? It would be a seam implementation bug ???

                • 5. Re: Transactional and EntityManager with Seam-Persistence+Weld+EclipseLink+Tomcat
                  Jason Porter Master

                  This blog may help a bit, looks like in Tomcat 7 they have a specialized tag for JTA support. You could do it without JTA (though, I'm not 100% sure we've tested Seam Persistence w/o JTA) by using a non-jta-datasource in the persistence.xml file.

                  • 6. Re: Transactional and EntityManager with Seam-Persistence+Weld+EclipseLink+Tomcat
                    Leonardo Costa Newbie

                    Now with OW2-JOTM the error was:


                    Caused by: java.lang.RuntimeException: org.jboss.weld.exceptions.NullInstanceException: WELD-000044 Unable to obtain instance from null
                         at org.jboss.seam.persistence.ManagedPersistenceContextBeanLifecycle.create(ManagedPersistenceContextBeanLifecycle.java:126)
                         at org.jboss.seam.persistence.ManagedPersistenceContextBeanLifecycle.create(ManagedPersistenceContextBeanLifecycle.java:46)
                         at org.jboss.seam.solder.bean.ImmutableBean.create(ImmutableBean.java:87)
                         at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:122)
                         at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:99)
                         at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:124)
                         at 
                    
                    org.jboss.weld.proxies.EntityManager$ManagedPersistenceContext$1537798873$Proxy$_$$_WeldClientProxy.createNamedQuery(EntityManager$ManagedPersistenceContext$1537798873$Proxy$_
                    
                    $$_WeldClientProxy.java)
                         at pacote.library.BaseDaoImp.getAll(BaseDaoImp.java:76)
                         at pacote.dao.-1608738265$Proxy$_$$_WeldSubclass.getAll(-1608738265$Proxy$_$$_WeldSubclass.java)
                         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                         at java.lang.reflect.Method.invoke(Unknown Source)
                         at org.jboss.interceptor.proxy.SimpleInterceptionChain.invokeNextInterceptor(SimpleInterceptionChain.java:114)
                         at org.jboss.interceptor.proxy.InterceptorInvocationContext.proceed(InterceptorInvocationContext.java:143)
                         at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:194)
                         at org.jboss.seam.transaction.Work.workInTransaction(Work.java:54)
                         at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:188)
                         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                         at java.lang.reflect.Method.invoke(Unknown Source)
                         at org.jboss.interceptor.proxy.InterceptorInvocation$InterceptorMethodInvocation.invoke(InterceptorInvocation.java:72)
                         at org.jboss.interceptor.proxy.SimpleInterceptionChain.invokeNextInterceptor(SimpleInterceptionChain.java:82)
                         at org.jboss.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:133)
                         at org.jboss.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:112)
                         at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:65)
                         at pacote.dao.-1608738265$Proxy$_$$_WeldSubclass.getAll(-1608738265$Proxy$_$$_WeldSubclass.java)
                         at pacote.controller.AdminAutorCtrl.todosAutores(AdminAutorCtrl.java:82)
                         at pacote.controller.AdminAutorCtrl.init(AdminAutorCtrl.java:38)
                         ... 88 more
                    Caused by: org.jboss.weld.exceptions.NullInstanceException: WELD-000044 Unable to obtain instance from null
                         at org.jboss.weld.bean.builtin.CallableMethodHandler.invoke(CallableMethodHandler.java:53)
                         at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:62)
                         at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:125)
                         at org.jboss.weldx.persistence.EntityManagerFactory$-2019871055$Proxy$_$$_Weld$Proxy$.createEntityManager(EntityManagerFactory$-2019871055$Proxy$_$$_Weld$Proxy$.java)
                         at org.jboss.seam.persistence.ManagedPersistenceContextBeanLifecycle.create(ManagedPersistenceContextBeanLifecycle.java:105)
                         ... 117 more
                    





                    I give up. I believe that Tomcat adoption is for simplify, not complicate matters further. According to the Seam Persistence Docs says, the thing looks pretty simple. Honestly speaking, the practice has become a martyrdom. I have two weeks researching and trying it. I reread and read these (among more other) docs up-down/down-up:


                    http://docs.jboss.org/seam/3/persistence/3.0.0.Final/reference/en-US/html_single/
                    http://seamframework.org/Seam3/PersistenceModule
                    http://seamframework.org/Seam3/PersistenceModuleHome
                    http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial



                    Unfortunately I will be content in use CDI only:


                    Producer:


                    public class PersistenceProducer {
                      private static final String PERSISTENCE_UNIT_NAME = "TemplateRichFacesPU";
                    
                      @Produces
                      @RequestScoped
                      public synchronized EntityManager createEntityManager() {
                        EntityManager entityManager;
                        entityManager = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME).createEntityManager();
                        return entityManager;
                      }
                    }
                    
                    




                    Interceptor:



                    @TransactionAttribute
                    @Interceptor
                    public class TransactionInterceptor implements Serializable {
                         private static final long serialVersionUID = 5978356159603989323L;
                    
                         @Inject
                         private     EntityManager entityManager;
                    
                         @AroundInvoke
                         public Object aroundInvoke(InvocationContext invocationContext) throws Exception {
                              // begin transaction
                              if (!entityManager.getTransaction().isActive()) {
                                   Util.log(getClass(), "Transaction begin");
                                   entityManager.getTransaction().begin();
                              }
                              try {
                                   // call transactional code block
                                   Object result = invocationContext.proceed();
                    (...)
                    


                    • 7. Re: Transactional and EntityManager with Seam-Persistence+Weld+EclipseLink+Tomcat
                      Jason Porter Master

                      Honestly, that's just trying to get EE stuff to work on Tomcat, it's been the same story for many years. If you choose a servlet container you have to roll your own App server basically.


                      As for the base CDI stuff, if that works, great! You may want to make sure to have a disposer method for the EM though.

                      • 8. Re: Transactional and EntityManager with Seam-Persistence+Weld+EclipseLink+Tomcat
                        Leonardo Costa Newbie

                        I understand... We started with Tomcat to have something small and end up turning a servlet container in a EE AS. The point is that we could have something simple in a servlet, simulating the EE environment. A middle ground. So the Seam Persistence proposal like seemed. It was fantastic!


                        - I can wait a maturation this tool in this sense?
                        - It may one day be easy to deploy in servlet container?

                        • 9. Re: Transactional and EntityManager with Seam-Persistence+Weld+EclipseLink+Tomcat
                          Jason Porter Master

                          If a servlet container profile comes out in EE7 we'll support it there (assuming CDI is part of the profile).  I heard TomEE was just certified Web Profile, you may want to take a look at that.

                          • 10. Re: Transactional and EntityManager with Seam-Persistence+Weld+EclipseLink+Tomcat
                            Lucas Ventura Carro Newbie

                            Hi!
                            Leonardo, if you're still reading this, I suggest you the project from this post:
                            http://seamframework.org/Community/SeamPersistence3Tomcat708#comment152705

                            Really, really useful to view which depencies are needed and how are configured :)