4 Replies Latest reply on Jul 22, 2010 10:00 AM by Marius Bogoevici

    EXTENDED @PersistenceContext @Produces

    Uros Majeric Newbie

      Hi,


      I have a question how to make a extended PersistenceContext producer.I want to have an annotation @ExtUserDatabase. I tried like this:


      @Stateful
      public class UserExtDatabaseProducer implements Serializable {
          @Produces @RequestScoped @ExtUserDatabase @PersistenceContext(unitName="userPU", type=PersistenceContextType.EXTENDED)
          public static EntityManager extendedItrackDatabase;
      }



      I have also problems with implementing producer for non extended entitymanager (from here)


      class UserDatabaseProducer {
         @Produces @UserDatabase @PersistenceContext(unitName="userPU")
         static EntityManager userDatabase;
      }



      I always getting an error:


      WELD-000044 Unable to obtain instance from org.jboss.weld.bean-...




      If I do it like so (without static), it works:


      public class UserDatabaseProducer implements Serializable {
          @Produces @UserDatabase @PersistenceContext(unitName="userPU")
          public EntityManager itrackDatabase;
      }



      thanks.

        • 1. Re: EXTENDED @PersistenceContext @Produces
          Pete Muir Master

          Can I see the whole stack trace of the exception please?

          • 2. Re: EXTENDED @PersistenceContext @Produces
            Uros Majeric Newbie

            This is a stack trace for 1st code snippet (EXTENDED):



            org.jboss.weld.exceptions.NullInstanceException: WELD-000044 Unable to obtain instance from org.jboss.weld.bean-/home/user/workspace/.../-ProducerField-si.irose.itrack.action.UserExtDatabaseProducer.extendedItrackDatabase
                    at org.jboss.weld.bean.builtin.CallableMethodHandler.invoke(CallableMethodHandler.java:60)
                    at org.jboss.weld.util.CleanableMethodHandler.invoke(CleanableMethodHandler.java:43)
                    at javax.persistence.EntityManager_$$_javassist_266.find(EntityManager_$$_javassist_266.java)
                    at si.irose.itrack.jpa.KegPLFacade.getEvents(KegPLFacade.java:228)
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                    at java.lang.reflect.Method.invoke(Method.java:597)
                    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1056)
                    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1128)
                    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5292)
                    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:615)
                    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
                    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:567)
                    at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:47)
                    at sun.reflect.GeneratedMethodAccessor383.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                    at java.lang.reflect.Method.invoke(Method.java:597)
                    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:858)
                    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
                    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:567)
                    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:157)
                    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:139)
                    at sun.reflect.GeneratedMethodAccessor382.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                    at java.lang.reflect.Method.invoke(Method.java:597)
                    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:858)
                    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
                    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:367)
                    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5264)
                    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5252)
                    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:190)
                    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84)
                    at $Proxy324.getEvents(Unknown Source)
                    at si.irose.itrack.jpa.__EJB31_Generated__KegPLFacade__Intf____Bean__.getEvents(Unknown Source)
                    at si.irose.itrack.jsf.KegPLController.getEvents(KegPLController.java:123)
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                    at java.lang.reflect.Method.invoke(Method.java:597)
                    at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:304)
                    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:298)
                    at org.jboss.weld.bean.proxy.ClientProxyMethodHandler.invoke(ClientProxyMethodHandler.java:113)
                    at org.jboss.weld.util.CleanableMethodHandler.invoke(CleanableMethodHandler.java:43)
                    at si.irose.itrack.jsf.KegPLController_$$_javassist_260.getEvents(KegPLController_$$_javassist_260.java)
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                    at java.lang.reflect.Method.invoke(Method.java:597)
                    at javax.el.BeanELResolver.getValue(BeanELResolver.java:302)
                    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
                    at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
                    at com.sun.el.parser.AstValue.getValue(AstValue.java:116)
                    at com.sun.el.parser.AstValue.getValue(AstValue.java:163)
                    at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
                    at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:71)
                    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:102)
                    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190)
                    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178)
                    at javax.faces.component.UIData.getValue(UIData.java:554)
                    at javax.faces.component.UIData.getDataModel(UIData.java:1248)
                    at javax.faces.component.UIData.setRowIndex(UIData.java:447)
                    at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:81)
                    at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:823)
                    at javax.faces.component.UIData.encodeBegin(UIData.java:937)
                    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:70)
                    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:61)
                    at org.primefaces.component.tabview.TabViewRenderer.encodeContents(TabViewRenderer.java:199)
                    at org.primefaces.component.tabview.TabViewRenderer.encodeMarkup(TabViewRenderer.java:130)
                    at org.primefaces.component.tabview.TabViewRenderer.encodeEnd(TabViewRenderer.java:47)
                    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:878)
                    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1620)
                    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
                    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
                    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380)
                    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
                    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:273)
                    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
                    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
                    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
                    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
                    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
                    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
                    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
                    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
                    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
                    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
                    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
                    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
                    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
                    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
                    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
                    at com.sun.grizzly.comet.CometEngine.executeServlet(CometEngine.java:473)
                    at com.sun.grizzly.comet.CometEngine.handle(CometEngine.java:341)
                    at com.sun.grizzly.comet.CometAsyncFilter.doFilter(CometAsyncFilter.java:84)
                    at com.sun.grizzly.arp.DefaultAsyncExecutor.
            SEVERE: invokeFilters(DefaultAsyncExecutor.java:161)
                    at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:137)
                    at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:88)
                    at com.sun.grizzly.http.TaskBase.run(TaskBase.java:189)
                    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
                    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
                    at java.lang.Thread.run(Thread.java:619)



            This is a stack trace for 2st code snippet (with static producer):



            org.jboss.weld.exceptions.NullInstanceException: WELD-000044 Unable to obtain instance from org.jboss.weld.bean-/home/user/workspace/.../-ProducerField-si.irose.itrack.action.UserDatabaseProducer.itrackDatabase
                    at org.jboss.weld.bean.builtin.CallableMethodHandler.invoke(CallableMethodHandler.java:60)
                    at org.jboss.weld.util.CleanableMethodHandler.invoke(CleanableMethodHandler.java:43)
                    at javax.persistence.EntityManager_$$_javassist_139.createNamedQuery(EntityManager_$$_javassist_139.java)
                    at si.irose.itrack.action.Producers.getKegVolumes(Producers.java:43)
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                    at java.lang.reflect.Method.invoke(Method.java:597)
                    at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:304)
                    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:298)
                    at org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:200)
                    at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstance(MethodInjectionPoint.java:164)
                    at org.jboss.weld.bean.ProducerMethod$1.produce(ProducerMethod.java:143)
                    at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:360)
                    at org.jboss.weld.context.AbstractMapContext.get(AbstractMapContext.java:112)
                    at org.jboss.weld.bean.proxy.ClientProxyMethodHandler.getProxiedInstance(ClientProxyMethodHandler.java:143)
                    at org.jboss.weld.bean.proxy.ClientProxyMethodHandler.invoke(ClientProxyMethodHandler.java:100)
                    at org.jboss.weld.util.CleanableMethodHandler.invoke(CleanableMethodHandler.java:43)
                    at org.javassist.tmp.java.lang.Iterable_$$_javassist_138.iterator(Iterable_$$_javassist_138.java)
                    at com.sun.faces.renderkit.SelectItemsIterator$IterableItemIterator.<init>(SelectItemsIterator.java:615)
                    at com.sun.faces.renderkit.SelectItemsIterator$IterableItemIterator.<init>(SelectItemsIterator.java:599)
                    at com.sun.faces.renderkit.SelectItemsIterator.initializeItems(SelectItemsIterator.java:210)
                    at com.sun.faces.renderkit.SelectItemsIterator.hasNext(SelectItemsIterator.java:135)
                    at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:760)
                    at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:842)
                    at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:296)
                    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:878)
                    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:295)
                    at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
                    at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
                    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)
                    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)
                    at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
                    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)
                    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:287)
                    at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:106)
                    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)
                    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)
                    at com.sun.faces.renderkit.html_basic.CompositeRenderer.encodeChildren(CompositeRenderer.java:75)
                    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)
                    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)
                    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
                    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
                    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380)
                    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
                    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:273)
                    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
                    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
                    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
                    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
                    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
                    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
                    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
                    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
                    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
                    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
                    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
                    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
                    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
                    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
                    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
                    at com.sun.grizzly.comet.CometEngine.executeServlet(CometEngine.java:473)
                    at com.sun.grizzly.comet.CometEngine.handle(CometEngine.java:341)
                    at com.sun.grizzly.comet.CometAsyncFilter.doFilter(CometAsyncFilter.java:84)
                    at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:161)
                    at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:137)
                    at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:88)
                    at com.sun.grizzly.http.TaskBase.run(TaskBase.java:189)
                    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
                    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
                    at java.lang.Thread.run(Thread.java:619)



            • 3. Re: EXTENDED @PersistenceContext @Produces
              Stuart Douglas Master

              According to the JPA spec you can't do extended persistence contexts outside of a stateful session bean.
              Also according to the CDI spec the container is not required to support resources with scope other than @Dependent.


              These is a preliminary version of the seam managed persistence context in seam-persistence availible, but you have to build it yourself:


              https://anonsvn.jboss.org/repos/seam/modules/persistence/trunk/


              You use it as follows:


              @RequestScoped
              @Produces
              @PersistenceUnit
              @ExtUserDatabase
              public EntityManagerFactory emf;
              
              



              and then you can inject the seam managed PC :


              @Inject
              @ExtUserDatabase
              EntityManager entityManager;
              


              • 4. Re: EXTENDED @PersistenceContext @Produces
                Marius Bogoevici Newbie

                Also, according to the spec, a non-static field of a session beans cannot be annotated @Produces (hence resources cannot be defined that way).