5 Replies Latest reply on Dec 19, 2007 6:12 PM by Pete Muir

    using two @Factory methods with two EntityManager objects

    Arbi Sookazian Master

      I needed another JPA query to populate a drop down listbox in my JSF. The table exists in a different DB than the original @Factory method query that populates the main form dataTable.

      soooooooooo............

      Is it "legal" to inject the EntityManager more than once in the case of multiple persistence units for multiple DB's? If not, can I create another SFSB and use the new EntityManager object for the new DB and inject it into the origianl SFSB? Assuming the context should stay the same for both (conversation scope).

      How can I do this using SMPC if it doesn't have the persistence unit element in the @In attribute for it? How does SMPC know what DB it's connected/configured to? I want to use FlushModeType.MANUAL to ensure there are no premature updates issued to the DB table(s).

      SFSB code:

      @PersistenceContext(unitName="boIcomsSecurityAudit", type=PersistenceContextType.EXTENDED)
       private EntityManager emICOMS;
      
       @PersistenceContext(unitName="coxIMDatasource", type=PersistenceContextType.EXTENDED)
       private EntityManager emCoxIM;
      
       @Begin(join=true, flushMode=FlushModeType.MANUAL) // <-- use this with SMPC
       //@Begin(join=true)
       @Factory("myAuditList")
       public void findAuditList()
       {
      
       Boolean hardCodeEmployeeId = Boolean.parseBoolean(SecurityAuditProperties.getProperty(SecurityAuditConstants.HARD_CODE_EMPLOYEE_ID));
       int employeeId;
      
       if (hardCodeEmployeeId) { //if true in props file then we're testing only...
       employeeId = 900050881; //using btkach id for now;
       }
       else {
       log.info("in getAuditList(): user.getUserId() = " + user.getUserId() + " user.getBillingId() = " + user.getBillingId());
      
       employeeId = getEmployeeId();
      
       }
       myAuditList = emICOMS.createQuery("SELECT gem, tsaw "+
       "FROM TblSecurityAuditWorking tsaw, "+
       "GlobalEmployeeMaster gem "+
       "WHERE tsaw.id.siteId = gem.id.siteId "+
       "AND tsaw.id.employeeNumber = gem.id.employeeNumber "+
       "AND tsaw.reportToId = :employeeId " +
       "ORDER BY tsaw.id.employeeNumber ASC")
       .setParameter("employeeId", employeeId)
       .getResultList();
      
       //instantiate null valued noteList
       noteAction.initialize(myAuditList);
      
       log.info("in findAuditList(): myAuditList.size() = " + myAuditList.size());
      
       noteLoadList = emICOMS.createQuery("SELECT saw.id.siteId, saw.id.employeeNumber, "+
       "("+
       "SELECT count(san) as AcctApprovedNoteCount "+
       "FROM TblSecurityAuditNote san "+
       "WHERE san.siteId = saw.id.siteId "+
       "AND san.employeeNumber = saw.id.employeeNumber "+
       "AND san.noteType = 'accountApproved' "+
       ") as AcctApprovedCount, "+
       "("+
       "SELECT count(san) as secLevelApprovedNoteCount "+
       "FROM TblSecurityAuditNote san "+
       "WHERE san.siteId = saw.id.siteId "+
       "AND san.employeeNumber = saw.id.employeeNumber "+
       "AND san.noteType = 'secLevelApproved' "+
       ") as secLevelApprovedCount, "+
       "("+
       "SELECT count(san) as adjLimitApprovedNoteCount "+
       "FROM TblSecurityAuditNote san "+
       "WHERE san.siteId = saw.id.siteId "+
       "AND san.employeeNumber = saw.id.employeeNumber "+
       "AND san.noteType = 'adjLimitApproved' "+
       ") as adjLimitApprovedCount "+
       "FROM TblSecurityAuditWorking saw")
       .getResultList();
      
      
      
       log.info("in findAuditList(): noteLoadList.size() = " + noteLoadList.size());
      
      
      
       }
      
       @Factory("peerList")
       public void getPeerList() {
      
       int employeeId = getEmployeeId();
      
       myAuditList = emCoxIM.createQuery("SELECT user1 "+
       "FROM User user1 "+
       "WHERE user1.hierarchyPath in "+
       "(SELECT user2.hierarchyPath "+
       "FROM User user2 "+
       "WHERE user2.employeeId = :employeeId) "+
       "ORDER BY user1.firstName ASC")
       .setParameter("employeeId", employeeId)
       .getResultList();
      
       log.info("in getPeerList(): peerList.size() = " + peerList.size());
       }
      
      
      


      I am getting the following exception when the newly added @Factory("peerList") method is executed:

      javax.ejb.EJBTransactionRolledbackException: org.hibernate.exception.GenericJDBCException: Cannot open connection
       at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
       at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:83)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
       at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:206)
       at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:119)
       at $Proxy110.getPeerList(Unknown Source)
       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.seam.util.Reflections.invoke(Reflections.java:21)
       at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
       at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
       at org.jboss.seam.ejb.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:41)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
       at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:106)
       at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
       at org.javassist.tmp.java.lang.Object_$$_javassist_1.getPeerList(Object_$$_javassist_1.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.seam.util.Reflections.invoke(Reflections.java:21)
       at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
       at org.jboss.seam.Component.callComponentMethod(Component.java:2074)
       at org.jboss.seam.Component.getInstanceFromFactory(Component.java:1918)
       at org.jboss.seam.Component.getInstance(Component.java:1855)
       at org.jboss.seam.Component.getInstance(Component.java:1832)
       at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
       at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)
       at org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:166)
       at org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:53)
       at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
       at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
       at org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
       at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
       at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
       at javax.faces.component.UISelectItems.getValue(UISelectItems.java:130)
       at com.sun.faces.renderkit.RenderKitUtils.getSelectItems(RenderKitUtils.java:323)
       at com.sun.faces.renderkit.html_basic.MenuRenderer.getOptionNumber(MenuRenderer.java:675)
       at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:793)
       at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:335)
       at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:896)
       at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
       at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
       at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
       at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:199)
       at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:194)
       at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:121)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
       at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:271)
       at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:117)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
       at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:271)
       at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:242)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
       at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
       at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
       at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
       at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
       at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at jcifs.http.NtlmHttpFilter.doFilter(NtlmHttpFilter.java:118)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
       at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
       at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
       at java.lang.Thread.run(Unknown Source)
      Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
       at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
       at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:73)
       at com.cox.beans.session.SecurityAuditAction.getPeerList(SecurityAuditAction.java:209)
       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.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
       at com.cox.beans.interceptor.ProfilingInterceptor.profile(ProfilingInterceptor.java:23)
       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.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
       at com.cox.beans.interceptor.LoggerInterceptor.profile(LoggerInterceptor.java:19)
       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.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
       at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
       at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
       at org.jboss.seam.persistence.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:48)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
       at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
       at org.jboss.seam.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:65)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
       at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
       at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:26)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
       at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:27)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
       at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:106)
       at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
       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.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
       at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:71)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
       ... 118 more
      Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection
       at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
       at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
       at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
       at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
       at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426)
       at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
       at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
       at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
       at org.hibernate.loader.Loader.doQuery(Loader.java:673)
       at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
       at org.hibernate.loader.Loader.doList(Loader.java:2220)
       at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
       at org.hibernate.loader.Loader.list(Loader.java:2099)
       at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
       at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
       at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
       at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
       at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
       at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
       ... 169 more
      Caused by: org.jboss.util.NestedSQLException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a2e0522:f0c:47685fc3:44 status: ActionStatus.ABORT_ONLY >); - nested throwable: (org.jboss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a2e0522:f0c:47685fc3:44 status: ActionStatus.ABORT_ONLY >))
       at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:94)
       at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:47)
       at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
       ... 183 more
      Caused by: org.jboss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a2e0522:f0c:47685fc3:44 status: ActionStatus.ABORT_ONLY >)
       at org.jboss.resource.connectionmanager.TxConnectionManager.managedConnectionReconnected(TxConnectionManager.java:343)
       at org.jboss.resource.connectionmanager.BaseConnectionManager2.reconnectManagedConnection(BaseConnectionManager2.java:518)
       at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:399)
       at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:842)
       at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:88)
       ... 185 more
      Caused by: javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a2e0522:f0c:47685fc3:44 status: ActionStatus.ABORT_ONLY >
       at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener$TransactionSynchronization.checkEnlisted(TxConnectionManager.java:744)
       at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener.enlist(TxConnectionManager.java:577)
       at org.jboss.resource.connectionmanager.TxConnectionManager.managedConnectionReconnected(TxConnectionManager.java:337)
       ... 189 more




        • 1. Re: using two @Factory methods with two EntityManager object
          Pete Muir Master

          Try using two SMPCs, this should work (I'm no EJB3 expert, so not sure why it doesn't work with two entity managers injected using @PersistenceContext, maybe ask on the EJB3 forum).

          • 2. Re: using two @Factory methods with two EntityManager object
            Arbi Sookazian Master

            I have successfully used two EntityManager objects pointed to two different DB's.

            In the case of transaction propagation via one SFSB method calling another one (in my case in the same SFSB), an XA datasource may be required to ensure the distributed transaction is supported.

            Gavin's suggestion: http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4064581#4064581

            I'm getting the exception due to the transaction attribute type settings (defaults to REQUIRED). It happens in different configurations (see test code below).

            I have found a workaround, see this thread:

            http://forum.java.sun.com/thread.jspa?messageID=10025073

            but I will definitely look into SMPC and there's some good info in the last chapter of the JPA + Hibernate book by Bauer and King. Basically configuration stuff in components.xml that I was not aware of. Hopefully I can configure two SMPC's to replace my existing two JPA PersistenceContext EntityManager objects.

            The main question is on page 813 of the JPA/Hibernate book, is it possible to configure multiple ManagedPersistenceContext (component tag) classes pointing to different EMF's?

            testPeerXA.xhtml:

            <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <ui:composition xmlns="http://www.w3.org/1999/xhtml"
             xmlns:s="http://jboss.com/products/seam/taglib"
             xmlns:ui="http://java.sun.com/jsf/facelets"
             xmlns:f="http://java.sun.com/jsf/core"
             xmlns:h="http://java.sun.com/jsf/html"
             xmlns:rich="http://richfaces.ajax4jsf.org/rich"
             xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
             xmlns:c="http://java.sun.com/jstl/core"
             template="layout/template.xhtml">
            
            
            
             <ui:define name="mainContent">
            
             <h:messages styleClass="message"/>
            
             <rich:panel>
             <h:form id="peerForm">
             <h:selectOneMenu id="selectPeer" value="#{peerAction.peer}">
             <f:selectItems value="#{peerAction.peersXA}" />
             </h:selectOneMenu>
             <h:outputText value="#{peerAction.employeeId}"/>
             </h:form>
             </rich:panel>
            
            
             </ui:define>
            </ui:composition>


            testPeer.xhtml:

            <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <ui:composition xmlns="http://www.w3.org/1999/xhtml"
             xmlns:s="http://jboss.com/products/seam/taglib"
             xmlns:ui="http://java.sun.com/jsf/facelets"
             xmlns:f="http://java.sun.com/jsf/core"
             xmlns:h="http://java.sun.com/jsf/html"
             xmlns:rich="http://richfaces.ajax4jsf.org/rich"
             xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
             xmlns:c="http://java.sun.com/jstl/core"
             template="layout/template.xhtml">
            
            
            
             <ui:define name="mainContent">
            
             <h:messages styleClass="message"/>
            
             <rich:panel>
             <h:form id="peerForm">
             <h:selectOneMenu id="selectPeer" value="#{peerAction.peer}">
             <f:selectItems value="#{peerAction.peers}" />
             </h:selectOneMenu>
             <h:outputText value="#{peerAction.employeeId}"/>
             </h:form>
             </rich:panel>
            
            
             </ui:define>
            </ui:composition>


            SFSB:

            package com.cox.beans.session;
            
            import java.util.List;
            import java.util.ListIterator;
            import java.util.Map;
            import java.util.TreeMap;
            
            import javax.ejb.Remove;
            import javax.ejb.Stateful;
            import javax.ejb.TransactionAttribute;
            import javax.ejb.TransactionAttributeType;
            import javax.persistence.EntityManager;
            import javax.persistence.PersistenceContext;
            import javax.persistence.PersistenceContextType;
            
            import org.jboss.seam.annotations.Destroy;
            import org.jboss.seam.annotations.In;
            import org.jboss.seam.annotations.Logger;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Out;
            import org.jboss.seam.log.Log;
            import org.jboss.seam.security.Identity;
            
            import com.cox.beans.entity.User;
            
            @Stateful
            @Name("peerAction")
            public class PeerAction implements PeerLocal {
            
             @PersistenceContext(unitName="coxIMDatasource", type=PersistenceContextType.EXTENDED)
             private EntityManager emCoxIM;
            
             @PersistenceContext(unitName="boIcomsSecurityAudit", type=PersistenceContextType.EXTENDED)
             private EntityManager emICOMS;
            
             @Logger
             private Log log;
            
             @In
             private Identity identity;
            
             private String networkId = "";
            
             private String peer = "";
            
             @Out
             private List peerList;
            
             @Remove @Destroy
             public void destroy() {
            
             }
             public String getPeer() {
             return "test";
             }
            
             public void setPeer(String peer) {
             this.peer = peer;
             }
            
             //results for testPeer.xhtml...
            
             /*got org.jboss.util.NestedSQLException: Could not enlist in transaction on entering meta-aware object!;
             when getPeers and getEmployeeId were both annotated with @TransactionAttribute(TransactionAttributeType.REQUIRED)
            
             works fine if getPeers set to REQUIRES_NEW and getEmployeeId set to REQUIRES_NEW
            
             works fine if getPeers set to REQUIRED and getEmployeeId set to REQUIRES_NEW
            
             works fine with:
            
             @TransactionAttribute(TransactionAttributeType.REQUIRED)
             public Map<String, Integer> getPeers() {
            
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public Integer getEmployeeId() { */
            
             //*************************************************************************************************************
            
             //results for testPeerXA.xhtml...
            
            /* got org.jboss.util.NestedSQLException: Could not enlist in transaction on entering meta-aware object!;
             when getPeersXA set to REQUIRED and getEmployeeId set to REQUIRES_NEW
            
             got org.jboss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!;
             when getPeersXA set to REQUIRES_NEW and getEmployeeId set to REQUIRES_NEW
            
             got org.jboss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!;
             when getPeersXA set to REQUIRES_NEW and getEmployeeId set to REQUIRED
            
             got org.jboss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!;
             with below config:
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public Map<String, Integer> getPeersXA() {
            
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public Integer getEmployeeId()
            
             below worked fine:
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public Map<String, Integer> getPeersXA() {
            
             @TransactionAttribute(TransactionAttributeType.REQUIRED)
             public Integer getEmployeeId() {
            
             */
            
             @TransactionAttribute(TransactionAttributeType.REQUIRED)
             public Map<String, Integer> getPeers() {
            
             long employeeId = 900050881;
            
             Map<String,Integer> map = new TreeMap<String,Integer>();
            
             peerList = emCoxIM.createQuery("SELECT user1 "+
             "FROM User user1 "+
             "WHERE user1.hierarchyPath in "+
             "(SELECT user2.hierarchyPath "+
             "FROM User user2 "+
             "WHERE user2.employeeId = :employeeId) "+
             "ORDER BY user1.firstName ASC")
             .setParameter("employeeId", employeeId)
             .getResultList();
            
             log.info("in getPeerList(): peerList.size() = " + peerList.size());
            
             ListIterator it = peerList.listIterator();
             while(it.hasNext()) {
             User user = (User)it.next();
             map.put(user.getFirstName()+ " " + user.getLastName(), user.getEmployeeId().intValue());
             }
            
             return map;
             }
            
             @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
             public Map<String, Integer> getPeersXA() {
            
             long employeeId = getEmployeeId();
            
             Map<String,Integer> map = new TreeMap<String,Integer>();
            
             peerList = emCoxIM.createQuery("SELECT user1 "+
             "FROM User user1 "+
             "WHERE user1.hierarchyPath in "+
             "(SELECT user2.hierarchyPath "+
             "FROM User user2 "+
             "WHERE user2.employeeId = :employeeId) "+
             "ORDER BY user1.firstName ASC")
             .setParameter("employeeId", employeeId)
             .getResultList();
            
             log.info("in getPeerList(): peerList.size() = " + peerList.size());
            
             ListIterator it = peerList.listIterator();
             while(it.hasNext()) {
             User user = (User)it.next();
             map.put(user.getFirstName()+ " " + user.getLastName(), user.getEmployeeId().intValue());
             }
            
             return map;
             }
            
            
            
             @TransactionAttribute(TransactionAttributeType.REQUIRED)
             public Integer getEmployeeId() {
             String networkId = getNetworkId()==null?"":getNetworkId();
            
             List myList = emICOMS.createQuery("from User u where u.networkId = :networkId").setParameter("networkId", networkId).getResultList();
             User newUser = (User)myList.get(0);
            
             Integer employeeId = newUser.getEmployeeId().intValue();
            
             return employeeId;
             }
            
             private String getNetworkId() {
             if (networkId.equals(""))
             return identity.getUsername();
             else
             return networkId;
             }
            
            }


            • 3. Re: using two @Factory methods with two EntityManager object
              Pete Muir Master

              You should ask these questions on the hibernate or EJB3 forums as you will probably get a better answer there.

              • 4. Re: using two @Factory methods with two EntityManager object
                Arbi Sookazian Master

                How will they tell me to use/configure SMPC, afaik it's specific to SEAM...

                Are there any example apps in the Seam distro that uses SMPC? I would hope so.....

                • 5. Re: using two @Factory methods with two EntityManager object
                  Pete Muir Master

                  I meant to do with XA datasources or with @PersistenceContext - SMPCs still use this stuff underneath.