3 Replies Latest reply on Jan 3, 2013 8:47 AM by nathan dennis

    Multiple Persistence Units / EntityManagers In Seam 3

    nathan dennis Expert

      Having a little trouble getting this going. I have two databases. Trying to use seam persistence and the documentation is shall we say... incomplete. Ive been doing this for years in seam 2.

       

      Here is what i have and what is happening.

       

       

      public class EntityManagerProducer {

       

       

          @ExtensionManaged

          @Produces// @HighlineDemo

          @PersistenceUnit(unitName="highlinePU")

          @ConversationScoped

          EntityManagerFactory hemf;

         

          @Produces

          @HighlineDemo

          @PersistenceContext(unitName = "highlinePU")

          private EntityManager hem;

         

          @ExtensionManaged

          @Produces

          @PersistenceUnit(unitName="webcarePU")

          @ConversationScoped

          EntityManagerFactory cemf;

         

          @Produces

          @Webcare

          @PersistenceContext(unitName = "webcarePU")

          private EntityManager ceM;

         

         

         

      }

        • 1. Re: Multiple Persistence Units / EntityManagers In Seam 3
          nathan dennis Expert

          apparently i hit cntl-s out of habit..

           

            <persistence-unit name="highlinePU" transaction-type="JTA">

                  <provider>org.hibernate.ejb.HibernatePersistence</provider>

                      <jta-data-source>java:jboss/highlineDatasource</jta-data-source>

                      <class>org.xxx.model.xxx.xxx</class>

                      <exclude-unlisted-classes >true</exclude-unlisted-classes>

                  <properties>

                      <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>

                      <property name="hibernate.hbm2ddl.auto" value="validate"/>

                      <property name="hibernate.show_sql" value="false"/>

                      <property name="hibernate.format_sql" value="true"/>

                      <property name="hibernate.default_schema" value="xxxx"/>

                      <property name="jboss.entity.manager.factory.jndi.name" value="java:/hemf"/>

                  </properties>

          </persistence-unit>

          <persistence-unit name="webcarePU" transaction-type="JTA">

              <provider>org.hibernate.ejb.HibernatePersistence</provider>

                  <jta-data-source>java:jboss/coreDatasource</jta-data-source>

                 

                 

                  <exclude-unlisted-classes >true</exclude-unlisted-classes>

              <properties>

                  <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>

                  <property name="hibernate.hbm2ddl.auto" value="validate"/>

                  <property name="hibernate.show_sql" value="false"/>

                  <property name="hibernate.format_sql" value="true"/>

                  <property name="hibernate.default_schema" value="xxxx"/>

                  <property name="hibernate.default_catalog" value="xxxx"/>

                  <property name="jboss.entity.manager.factory.jndi.name" value="java:/cemf"/>

              </properties>

          </persistence-unit>

           

           

          wanted to inject using something like

          @Inject @HighlineDemo
          private EntityManager hem;

           

           

           

          but instead i get this error

          16:30:59,042 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[xxxxreports].[/].[Faces Servlet]] (ajp-/10.2.8.2:8009-1) Servlet.service() for servlet Faces Servlet threw exception: javax.enterprise.event.ObserverException

              at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.6.0_26]

              at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) [rt.jar:1.6.0_26]

              at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) [rt.jar:1.6.0_26]

              at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [rt.jar:1.6.0_26]

              at java.lang.Class.newInstance0(Class.java:355) [rt.jar:1.6.0_26]

              at java.lang.Class.newInstance(Class.java:308) [rt.jar:1.6.0_26]

              at org.jboss.weld.util.reflection.SecureReflections$16.work(SecureReflections.java:344) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInstantiation(SecureReflectionAccess.java:173) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.jboss.weld.util.reflection.SecureReflections.newInstance(SecureReflections.java:341) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.jboss.weld.injection.Exceptions.rethrowException(Exceptions.java:33) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.jboss.weld.injection.Exceptions.rethrowException(Exceptions.java:73) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:162) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:245) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:233) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:213) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.jboss.weld.manager.BeanManagerImpl.notifyObservers(BeanManagerImpl.java:590) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.jboss.weld.manager.BeanManagerImpl.fireEvent(BeanManagerImpl.java:580) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.jboss.weld.manager.BeanManagerImpl.fireEvent(BeanManagerImpl.java:575) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.jboss.solder.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:74) [solder-impl-3.1.0.Final.jar:3.1.0.Final]

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.16.Final.jar:]

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.16.Final.jar:]

              at org.jboss.solder.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:74) [solder-impl-3.1.0.Final.jar:3.1.0.Final]

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.16.Final.jar:]

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.16.Final.jar:]

              at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:126) [prettyfaces-jsf2-3.3.2.jar:]

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.16.Final.jar:]

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.16.Final.jar:]

              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.16.Final.jar:]

              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.16.Final.jar:]

              at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.2.Final.jar:7.1.2.Final]

              at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.2.Final.jar:7.1.2.Final]

              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.16.Final.jar:]

              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.16.Final.jar:]

              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.16.Final.jar:]

              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.16.Final.jar:]

              at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:505) [jbossweb-7.0.16.Final.jar:]

              at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:452) [jbossweb-7.0.16.Final.jar:]

              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:931) [jbossweb-7.0.16.Final.jar:]

              at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_26]

          Caused by: javax.servlet.ServletException: org.jboss.weld.exceptions.AmbiguousResolutionException: WELD-001318 Cannot resolve an ambiguous dependency between [Resource Producer Field [EntityManagerFactory] with qualifiers [@Any @Default] declared as [[field] @PersistenceUnit @ExtensionManaged @Produces org.xxxx.persistence.EntityManagerProducer.hemf], Resource Producer Field [EntityManagerFactory] with qualifiers [@Any @Default] declared as [[field] @PersistenceUnit @ExtensionManaged @Produces org.xxxx.persistence.EntityManagerProducer.cemf]]

              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:606) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.16.Final.jar:]

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.16.Final.jar:]

              at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.16.Final.jar:]

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.16.Final.jar:]

              at org.jboss.solder.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65) [solder-impl-3.1.0.Final.jar:3.1.0.Final]

              ... 20 more

          Caused by: java.lang.RuntimeException: org.jboss.weld.exceptions.AmbiguousResolutionException: WELD-001318 Cannot resolve an ambiguous dependency between [Resource Producer Field [EntityManagerFactory] with qualifiers [@Any @Default] declared as [[field] @PersistenceUnit @ExtensionManaged @Produces org.xxxx.persistence.EntityManagerProducer.hemf], Resource Producer Field [EntityManagerFactory] with qualifiers [@Any @Default] declared as [[field] @PersistenceUnit @ExtensionManaged @Produces org.xxxx.persistence.EntityManagerProducer.cemf]]

              at org.jboss.seam.persistence.ManagedPersistenceContextBeanLifecycle.create(ManagedPersistenceContextBeanLifecycle.java:111) [seam-persistence-3.1.0.Final.jar:3.1.0.Final]

              at org.jboss.seam.persistence.ManagedPersistenceContextBeanLifecycle.create(ManagedPersistenceContextBeanLifecycle.java:45) [seam-persistence-3.1.0.Final.jar:3.1.0.Final]

              at org.jboss.solder.bean.ImmutableBean.create(ImmutableBean.java:81) [solder-impl-3.1.0.Final.jar:3.1.0.Final]

              at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:68) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:637) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:664) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.jboss.weld.bean.builtin.InstanceImpl.iterator(InstanceImpl.java:133) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.jboss.seam.persistence.PersistenceContextsImpl.beforeRender(PersistenceContextsImpl.java:117) [seam-persistence-3.1.0.Final.jar:3.1.0.Final]

              at org.jboss.seam.persistence.PersistenceContextsImpl$Proxy$_$$_WeldClientProxy.beforeRender(PersistenceContextsImpl$Proxy$_$$_WeldClientProxy.java) [seam-persistence-3.1.0.Final.jar:3.1.0.Final]

              at org.jboss.seam.faces.transaction.TransactionPhaseListener.handleTransactionsBeforePhase(TransactionPhaseListener.java:78) [seam-faces-3.1.0.Final.jar:3.1.0.Final]

              at org.jboss.seam.faces.transaction.TransactionPhaseListener.beforePhase(TransactionPhaseListener.java:64) [seam-faces-3.1.0.Final.jar:3.1.0.Final]

              at org.jboss.seam.faces.event.DelegatingPhaseListener.beforePhase(DelegatingPhaseListener.java:43) [seam-faces-3.1.0.Final.jar:3.1.0.Final]

              at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]

              ... 26 more

          Caused by: org.jboss.weld.exceptions.AmbiguousResolutionException: WELD-001318 Cannot resolve an ambiguous dependency between [Resource Producer Field [EntityManagerFactory] with qualifiers [@Any @Default] declared as [[field] @PersistenceUnit @ExtensionManaged @Produces org.xxxx.persistence.EntityManagerProducer.hemf], Resource Producer Field [EntityManagerFactory] with qualifiers [@Any @Default] declared as [[field] @PersistenceUnit @ExtensionManaged @Produces org.xxxx.persistence.EntityManagerProducer.cemf]]

              at org.jboss.weld.manager.BeanManagerImpl.resolve(BeanManagerImpl.java:1067) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]

              at org.jboss.seam.persistence.ManagedPersistenceContextBeanLifecycle.getEntityManagerFactory(ManagedPersistenceContextBeanLifecycle.java:171) [seam-persistence-3.1.0.Final.jar:3.1.0.Final]

              at org.jboss.seam.persistence.ManagedPersistenceContextBeanLifecycle.create(ManagedPersistenceContextBeanLifecycle.java:94) [seam-persistence-3.1.0.Final.jar:3.1.0.Final]

              ... 41 more

           

           

          any light you could shed on this error would be greatly apprishiated. I saw a simular error that had to do with the jboss as 7.1.1.final version and it was suppostly fixed according to jason porter in the 7.1.2.final tag. so i built that version and deployed the app to it and got the same error. this app works find if i remove the second entityManager. Ideas?

          • 2. Re: Multiple Persistence Units / EntityManagers In Seam 3
            Terrence Curran Newbie

            Did you try it like this?: 

             

             

            {code:java}

            public class EntityManagerProducer {

             

              @PersistenceContext(unitName = "highlinePU")

              private EntityManager hem;

              

              @PersistenceContext(unitName = "webcarePU")

              private EntityManager ceM;

             

              @Produces
              @HighlineDemo
              public EntityManager getHighlineEntityManager() {

                 return hem;
              }

             

              @Produces
              @Webcare
              public EntityManager getWebcareEntityManager() {

                return ceM;
              }

            }

            {code}

             

            • 3. Re: Multiple Persistence Units / EntityManagers In Seam 3
              nathan dennis Expert

              it was my understanding that you had to use @Input to make use of seam persistence. otherwise we are just injecting a regular entityManager.

               

              but this problem persists... no pun intended.