6 Replies Latest reply on Feb 4, 2008 4:59 PM by asookazian

    SMPC and could not enlist in transaction exception

    asookazian

      I'm not sure exactly what the root cause of this is and I'll try my best to explain this in detail. I had added three SMPC's in my components.xml as follows (and everything as far as transaction/persistence was working fine):

      <persistence:managed-persistence-context name="CoxIMEntityManager"
       auto-create="true"
       persistence-unit-jndi-name="java:/securityAuditCoxIMEntityManagerFactory"/>
      
       <persistence:managed-persistence-context name="CoxDSSEntityManager"
       auto-create="true"
       persistence-unit-jndi-name="java:/securityAuditCoxDSSEntityManagerFactory"/>
      
       <persistence:managed-persistence-context name="BoIcomsEntityManager"
       auto-create="true"
       persistence-unit-jndi-name="java:/securityAuditBoIcomsEntityManagerFactory"/>


      I'm not even sure it's necessary to do this (have three SMPC's, perhaps only one would suffice for this app as all db's are on the same db server). That's my first question. What is the recommended # of SMPC's per db/server combo? 1:1?? 2nd question is why exactly am I getting the exception below when I make the components.xml change as described below? If it depends on how many and which SMPC's you are injecting per Action SFSB/SLSB then plz let me know and I will post the add'l code.

      Note that all these persistence units point to datasources that are db's on the same server.

      persistence.xml:
       <persistence-unit name="boIcomsSecurityAudit">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/boIcomsSecurityAuditDatasource</jta-data-source>
       <properties>
       <property name="jboss.entity.manager.factory.jndi.name" value="java:/securityAuditBoIcomsEntityManagerFactory"/>
       </properties>
       </persistence-unit>
      
      
       <persistence-unit name="coxDSSDatasource">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/coxDSSDatasource</jta-data-source>
       <properties>
       <property name="jboss.entity.manager.factory.jndi.name" value="java:/securityAuditCoxDSSEntityManagerFactory"/>
       </properties>
       </persistence-unit>
      
       <persistence-unit name="coxIMDatasource">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/coxIMDatasource</jta-data-source>
       <properties>
       <property name="jboss.entity.manager.factory.jndi.name" value="java:/securityAuditCoxIMEntityManagerFactory"/>
       </properties>
       </persistence-unit>


      *-ds.xml:
      <local-tx-datasource>
       <jndi-name>boIcomsSecurityAuditDatasource</jndi-name>
       <connection-url>jdbc:sqlserver://CORG0DV01:1433;databaseName=boIcomsSecurityAudit</connection-url>
       <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
       <user-name>_AppUser_JavaTestAcct</user-name>
       <password>JavaTestAcct</password>
       </local-tx-datasource>
      
      
       <local-tx-datasource>
       <jndi-name>coxDSSDatasource</jndi-name>
       <connection-url>jdbc:sqlserver://CORG0DV01:1433;databaseName=coxDSS</connection-url>
       <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
       <user-name>_AppUser_JavaTestAcct</user-name>
       <password>JavaTestAcct</password>
       </local-tx-datasource>
      
       <local-tx-datasource>
       <jndi-name>coxIMDatasource</jndi-name>
       <connection-url>jdbc:sqlserver://CORG0DV01:1433;databaseName=coxIM</connection-url>
       <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
       <user-name>_AppUser_JavaTestAcct</user-name>
       <password>JavaTestAcct</password>
       </local-tx-datasource>


      I noticed that I had one of the SMPC's coded incorrectly in the components.xml.

      This:

      <persistence:managed-persistence-context name="BoIcomsEntityManager"
       auto-create="true"
       persistence-unit-jndi-name="java:/securityAuditBoIcomsEntityManagerFactory"/>


      *was* this:

      <persistence:managed-persistence-context name="BoIcomsEntityManager"
       auto-create="true"
       persistence-unit-jndi-name="java:/securityAuditCoxIMEntityManagerFactory"/>


      I wasn't getting the exception below with the latter config of BoIcomsEntityManager above.

      stack trace:

      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:76)
       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:106)
       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:204)
       at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:100)
       at $Proxy112.findAuditList(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_2.findAuditList(Object_$$_javassist_2.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.parser.AstNotEqual.getValue(AstNotEqual.java:21)
       at org.jboss.el.parser.AstAnd.getValue(AstAnd.java:21)
       at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
       at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
       at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:370)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:880)
       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:433)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
       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:241)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
       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.findAuditList(SecurityAuditAction.java:165)
       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:56)
       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:57)
       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)
       ... 115 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)
       ... 166 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: a2e052a:ca9:47a39190:4b 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: a2e052a:ca9:47a39190:4b 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)
       ... 180 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: a2e052a:ca9:47a39190:4b 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)
       ... 182 more
      Caused by: javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a2e052a:ca9:47a39190:4b 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)
       ... 186 more


        • 1. Re: SMPC and could not enlist in transaction exception
          asookazian

          according to section 8.3.1 of the Seam 2.0.0.GA ref doc, the example refers to a bookingDatabase for the SMPC tag config in components.xml.

          What is the recommended best practice for handling situations like my post above where you need SMPC (for whatever reason, say so your conversation's inputted data is not persisted to the db until the conversation is ended, thus requiring flushMode=MANUAL, etc.) and your back-end consists of multiple db's?

          How many SMPC's do we need to create/config then? And it should depend on how many db servers are involved in the use-case/transaction.

          what about web services? do they require SMPC as well? now that Seam added a feature of conversational web service methods...

          • 2. Re: SMPC and could not enlist in transaction exception
            asookazian

            Is it correct to assume that "create=true" is unnecessary for the @In annotation below b/c it is already in the components.xml (auto-create="true")??

            SecurityAuditAction:

            package com.cox.beans.session;
            
            import java.sql.Timestamp;
            import java.util.ArrayList;
            import java.util.Date;
            import java.util.List;
            
            import javax.annotation.PostConstruct;
            import javax.annotation.PreDestroy;
            import javax.ejb.PostActivate;
            import javax.ejb.PrePassivate;
            import javax.ejb.Remove;
            import javax.ejb.Stateful;
            import javax.ejb.TransactionAttribute;
            import javax.ejb.TransactionAttributeType;
            import javax.faces.model.SelectItem;
            import javax.persistence.EntityManager;
            
            import org.jboss.seam.annotations.Begin;
            import org.jboss.seam.annotations.Destroy;
            import org.jboss.seam.annotations.End;
            import org.jboss.seam.annotations.Factory;
            import org.jboss.seam.annotations.FlushModeType;
            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.annotations.datamodel.DataModel;
            import org.jboss.seam.annotations.datamodel.DataModelSelectionIndex;
            import org.jboss.seam.log.Log;
            import org.jboss.seam.security.Identity;
            import org.jboss.seam.web.Session;
            
            import com.cox.beans.entity.TblSecurityAuditNote;
            import com.cox.beans.entity.TblSecurityAuditWorking;
            import com.cox.beans.entity.User;
            import com.cox.util.SecurityAuditConstants;
            import com.cox.util.SecurityAuditProperties;
            
            
            
            
            @Stateful
            @Name("securityAuditAction")
            public class SecurityAuditAction implements SecurityAuditLocal {
            
             @Logger
             private Log log;
            
             @In
             private Identity identity;
            
             // using EXTENDED for PersistenceContextType was causing premature update transaction commit to DB when clicking 'no' on radio button...
             // 12/17/07 - org.hibernate.PersistentObjectException: detached entity passed to persist: com.cox.beans.entity.TblSecurityAuditNote
             /*
             * http://www.jboss.org/index.html?module=bb&op=viewtopic&t=107263
            
             “what are the reasons for the PersistentObjectException to occur?�
            
             “If the entity is detached ;) You need to make sure your persistence context spans the life all
             the operations you perform with that instance of the entity.� <-- P. Muir
            
             attempting to fix this exception by using Extended PersistenceContextType again... now entites will not detach from persistence context
            
             12/18/07 - now attempting SMPC as per section 8.3.3 of Seam ref pdf: we would prefer that all changes are held in memory and only written
             to the database when the conversation ends successfully. This allows for truly atomic conversations
             */
            
             //@PersistenceContext(unitName="boIcomsSecurityAudit", type=PersistenceContextType.EXTENDED)
             //private EntityManager emICOMS;
            
             @In(value="BoIcomsEntityManager")
             EntityManager emICOMS;
            
             //@In(required=false) @Out
             @In(required=false)
             private User user;
            
             @In(required=false)
             private List<TblSecurityAuditNote[]> noteList = new ArrayList<TblSecurityAuditNote[]>();
            
             @In(create=true)
             private NoteLocal noteAction;
            
             @In(create=true)
             private PeerLocal peerAction;
            
             private List<SelectItem> myRadioButtonList;
            
             private List noteLoadList;
            
             @DataModel(value="myAuditList")
             private List myAuditList;
            
             private String networkId = "";
            
             @DataModelSelectionIndex(value="myAuditList")
             private int currentRowNum;
            
             //adding empty constructor callback lifecycle methods for debugging purposes (interceptor will output when they get called)
            
             public SecurityAuditAction() {}
            
             @PostConstruct
             public void postConstruct() {
             log.info("in postConstruct");
             }
            
             @PostActivate
             public void postActivate() {
             log.info("in postActivate");
             }
            
             @PrePassivate
             public void prePassivate() {
             log.info("in prePassivate");
            
             }
            
             @PreDestroy
             public void preDestroy() {
             log.info("in preDestroy");
            
             }
            
             private Object[] getMyAuditListSelection() {
             return (Object[])myAuditList.get(currentRowNum);
             }
            
             @End
             public void invalidateSession() {
            
             //user selected a peer from peer selectOneMenu, so invalidate session and continue...
            
             Session.instance().invalidate();
            
             //findAuditList2();
             }
            
             // 12-03/07 - got following exception when I clicked cancel in modalPanel:
             // Caused by java.lang.IllegalStateException with message: "begin method invoked from a long-running conversation, try using @Begin(join=true) on method: findAuditList"
             // adding join=true...
            
             @Begin(join=true, flushMode=FlushModeType.MANUAL) // <-- use this with SMPC
             @Factory("myAuditList")
             public void findAuditList()
             {
             Boolean hardCodeEmployeeId = Boolean.parseBoolean(SecurityAuditProperties.getPropertyObject().getProperty(SecurityAuditConstants.HARD_CODE_EMPLOYEE_ID));
             Integer employeeId;
            
             if (hardCodeEmployeeId) { //if true in props file then we're testing only...
            
             employeeId = peerAction.getEmployeeId().intValue();
            
             if (employeeId == null) {
            
             employeeId = Integer.parseInt(SecurityAuditProperties.getPropertyObject().getProperty(SecurityAuditConstants.EMPLOYEE_ID)); //using btkach id for now;
             }
             }
             else {
            
             employeeId = peerAction.getEmployeeId().intValue();
            
             }
             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();
            
             //reset/clear instance variables in Note SFSB...
             noteAction.reset();
            
             //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 "+
             "WHERE saw.reportToId = :employeeId")
             .setParameter("employeeId", employeeId)
             .getResultList();
            
            
            
             log.info("in findAuditList(): noteLoadList.size() = " + noteLoadList.size());
            
            
            
             }
            
             public Boolean getLoadedNote(Integer rowIndex, String colName) {
             if (rowIndex > -1) {
             Object[] myArray = (Object[])noteLoadList.get(rowIndex);
             Long count = (Long)myArray[convertColName(colName).intValue()];
             if (count > 0)
             return true;
             else
             return false;
             }
             else
             return false;
             }
            
             private Integer convertColName(String colName) {
            
             if (SecurityAuditConstants.COL_ONE_NAME.equals(colName)) {
             return SecurityAuditConstants.SECURITY_ACTION_COL_ONE_VALUE;
             }
             else if (SecurityAuditConstants.COL_TWO_NAME.equals(colName)) {
             return SecurityAuditConstants.SECURITY_ACTION_COL_TWO_VALUE;
             }
             else if (SecurityAuditConstants.COL_THREE_NAME.equals(colName)) {
             return SecurityAuditConstants.SECURITY_ACTION_COL_THREE_VALUE;
             }
             else
             return 0;
            
             }
            
             public List<SelectItem> getSecurityAuditRadioButtons() {
             myRadioButtonList = new ArrayList<SelectItem>();
             myRadioButtonList.add(new SelectItem("true", "Yes", "Yes it is"));
             myRadioButtonList.add(new SelectItem("false", "No", "No it isn't"));
             return myRadioButtonList;
             }
            
             public String getHeader() {
             return "Please enter your note for the associate";
             }
            
             @End
             @TransactionAttribute(TransactionAttributeType.REQUIRED) //REQUIRED is default, but added for clarity
             public void submit() {
            
             Object[] myAuditListSelection = getMyAuditListSelection();
            
             TblSecurityAuditWorking tsaw = (TblSecurityAuditWorking)myAuditListSelection[1];
            
             //determine what status to assign to each row/employee based on answers to radio buttons...
            
             //RULES: if yes/yes/yes --> green
             // if any no(s) --> yellow
             // if none selected --> red
            
             Boolean icomsAccountApproved = tsaw.getIcomsAccountApproved()==null?false:tsaw.getIcomsAccountApproved();
             Boolean adjustmentLimitApproved = tsaw.getAdjustmentLimitApproved()==null?false:tsaw.getAdjustmentLimitApproved();
             Boolean securityLevelApproved = tsaw.getSecurityLevelApproved()==null?false:tsaw.getSecurityLevelApproved();
            
             if ( icomsAccountApproved && adjustmentLimitApproved && securityLevelApproved ) {
             //green
             tsaw.setAuditProgress(SecurityAuditConstants.AUDIT_COMPLETE);
             }
             else if ( !icomsAccountApproved || !adjustmentLimitApproved || !securityLevelApproved ) {
             //yellow
             tsaw.setAuditProgress(SecurityAuditConstants.AUDIT_WAITING_ICOMS);
             }
             else {
             //yellow
             tsaw.setAuditProgress(SecurityAuditConstants.AUDIT_WAITING_ICOMS);
             }
            
             Date myDate = new Date();
             Long myTime = myDate.getTime();
             Timestamp myTimeStamp = new Timestamp(myTime);
             tsaw.setTimeStamp(myTimeStamp);
            
             emICOMS.merge(tsaw);
            
             //check to see if there are any notes for each radio button for this employee/row
             //then update/insert accordingly
            
             //TO DO: move the hard-coding 3 for # of updateable columns in dataTable to resource bundle
            
             // TO DO: noteAction.submit() was moved to action listener attribute in modalPanels...
             //call submit to ensure new note is added to array
             //noteAction.submit();
            
             for (int colNum = 0; colNum < SecurityAuditConstants.MAX_COLUMNS; colNum++) {
            
             TblSecurityAuditNote note = getTblSecurityAuditNote(currentRowNum, colNum);
            
             if (note != null) {
            
             log.info("myNotes["+currentRowNum+"]["+colNum+"]: noteId = " + note.getNoteId() + " noteText = " + note.getNoteText());
            
             emICOMS.persist(note);
            
             //fix transaction failed when user inserts multiple notes for two columns in the same row by setting current note in array to null...
             //this was happening when you add a note to col C and save, then add a note to col B and save (the loop
             //was calling persist(note) on an already persisted entity and there would be a primary key violation
             //so Hibernate throws an exception:
             //org.hibernate.PersistentObjectException: detached entity passed to persist: com.cox.beans.entity.TblSecurityAuditNote
            
             /* AS - 01/16/08 - commenting to test to see if this code block is the root cause of the
             * not reRendering of the graphic icon when you enter the first note and submit in modalPanel
             * results: it was the root cause! leaving commented as the above transaction failed problem is now not occurring
             TblSecurityAuditNote[] myNoteArray = noteList.get(currentRowNum);
             myNoteArray[colNum] = null;
             noteList.set(currentRowNum, myNoteArray);
             */
             }
             }
            
             emICOMS.flush();
            
             }
            
             private TblSecurityAuditNote getTblSecurityAuditNote(Integer rowIndex, Integer colNum) {
             rowIndex = rowIndex==null?0:rowIndex;
             colNum = colNum==null?0:colNum;
            
             if (noteList != null) {
             try {
             TblSecurityAuditNote[] myNoteArray = noteList.get(rowIndex);
             return myNoteArray[colNum];
             }
             catch (IndexOutOfBoundsException e) {
             if (rowIndex != null && rowIndex < 0) {
             e.printStackTrace();
             throw e;
             }
             return null;
             }
             }
             else {
             return null;
             }
             }
            
             public String processGraphicImage(Integer auditProgress) {
             switch (auditProgress) {
             case 0: return SecurityAuditConstants.RED_GRAPHIC;
             case 1: return SecurityAuditConstants.YELLOW_GRAPHIC;
             case 2: return SecurityAuditConstants.GREEN_GRAPHIC;
             default: return SecurityAuditConstants.RED_GRAPHIC;
             }
             }
            
             public String processNoteImage() {
             return SecurityAuditConstants.NOTE_GRAPHIC;
             }
            
             private String getNetworkId() {
             if (networkId.equals(""))
             return identity.getUsername();
             else
             return networkId;
             }
            
             private void setNetworkId(String networkId) {
             //log.info("in setNetworkId(): networkId = " + networkId);
             this.networkId = networkId;
             }
            
             private 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;
             }
            
            
             @Remove @Destroy
             public void destroy() {
            
             }
            
            
            
            
            }


            • 3. Re: SMPC and could not enlist in transaction exception
              pmuir

              1) >= 1 SMPC per db (unless you use something like Shards or Metamatrix)

              2) I'm not 100% sure, but I think you need to use XA transactions if you are using multiple datasources

              3) If something is @AutoCreate, create=true is redundant, yes.

              • 4. Re: SMPC and could not enlist in transaction exception
                asookazian

                 

                "pete.muir@jboss.org" wrote:
                1) >= 1 SMPC per db (unless you use something like Shards or Metamatrix)

                why would you ever need more than one SMPC per db? I can understand having 1 or 2 SMPC's for 2 db's if the db's are on the same server...

                2) I'm not 100% sure, but I think you need to use XA transactions if you are using multiple datasources

                AFAIK, XA transactions are necessary only when supporting/using distributed transactions (such as when method A with a required transaction annotation - e.g. REQUIRES or REQUIRESNEW - propagates its transaction to another EntityManager CRUD operation in method B that is called by method A and also requires a transaction). Then a XA datasource is required to enable 2 phase commit protocol where the transaction mgr coordinates commits with the resource mgr's (for the db's).


                3) If something is @AutoCreate, create=true is redundant, yes.

                this makes sense. thx.

                • 5. Re: SMPC and could not enlist in transaction exception
                  pmuir

                  You might want to apply a hibernate filter to one SMPC but not the other.

                  • 6. Re: SMPC and could not enlist in transaction exception
                    asookazian

                    After doing some root-cause analysis I was able to reproduce the behavior with a simpler set of code as below. The key thing here is that by default, the transaction type in EJB3/JPA is REQUIRES. If you set getNoteLogList() and getPeers() methods' transaction types to REQUIRES_NEW, the exception is *not* reproduceable.

                    This indicates that when use case is executed (user navigates to JSF), there is a distributed transaction that is happening b/c BoIcomsEntityManager SMPC is based on db 1 and CoxIMEntityManager SMPC is based on db 2 and the first transaction is propagating to the 2nd one.

                    .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:form>
                    
                     <!-- <h:dataTable value="#{testPeerAction.getPeers()}"/> -->
                    
                     <h:dataTable value="#{testUserBean.getNoteLogList()}"/>
                    
                     <h:dataTable value="#{testPeerAction.getPeers()}"/>
                    
                     </h:form>
                    
                    </ui:define>
                    </ui:composition>
                    


                    It doesn't matter what order the methods are listed in the above .xhtml (you will get the exception for the latter method).

                    TestUserBean SFSB:

                    import java.util.List;
                    
                    import javax.ejb.Remove;
                    import javax.ejb.Stateful;
                    import javax.persistence.EntityManager;
                    
                    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;
                    
                    
                    @Stateful
                    @Name("testUserBean")
                    public class TestUserBean implements TestUserLocal {
                    
                     @Logger
                     private Log log;
                    
                     @In(value="BoIcomsEntityManager")
                     EntityManager emICOMS;
                    
                     @Out(required=false)
                     private List testNoteLogList;
                    
                     //@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
                     public List getNoteLogList() {
                     log.info("in getNoteLogList()");
                    
                     testNoteLogList = emICOMS.createQuery("SELECT san "+
                     "FROM TblSecurityAuditNote san")
                     .getResultList();
                    
                     log.info("in getNoteLogList(): testNoteLogList.size() = " + testNoteLogList.size());
                    
                     return testNoteLogList;
                    
                     }
                    
                     @Remove @Destroy
                     public void destroy() {}
                    
                    }


                    TestPeerAction SFSB:

                    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.persistence.EntityManager;
                    
                    import org.jboss.seam.ScopeType;
                    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.Scope;
                    import org.jboss.seam.log.Log;
                    
                    import com.cox.beans.entity.User;
                    import com.cox.util.SecurityAuditConstants;
                    import com.cox.util.SecurityAuditProperties;
                    
                    @Stateful
                    @Name("testPeerAction")
                    //using Session scope so that the processValueChange instance variables will not be nulled out...
                    @Scope(ScopeType.SESSION)
                    public class TestPeerAction implements TestPeerLocal {
                    
                     @In(value="CoxIMEntityManager")
                     EntityManager emCoxIM;
                    
                     @Logger
                     private Log log;
                     private Long employeeId;
                     private List peerList;
                    
                     @Remove @Destroy
                     public void destroy() {
                    
                     }
                    
                     //@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
                     public Map<String, Long> getPeers() {
                    
                     Boolean hardCodeEmployeeId = Boolean.parseBoolean(SecurityAuditProperties.getPropertyObject().getProperty(SecurityAuditConstants.HARD_CODE_EMPLOYEE_ID));
                    
                     if (hardCodeEmployeeId && employeeId == null) {
                     employeeId = Long.parseLong(SecurityAuditProperties.getPropertyObject().getProperty(SecurityAuditConstants.EMPLOYEE_ID));
                     }
                    
                     Map<String,Long> map = new TreeMap<String,Long>();
                    
                     peerList = emCoxIM.createQuery("SELECT user1 "+
                     "FROM User user1 "+
                     "WHERE user1.hierarchyPath in "+
                     "(SELECT user2.hierarchyPath "+
                     "FROM User user2 "+
                     "WHERE user2.employeeId = :employeeId "+
                     "AND user2.isActive = 1) "+
                     "AND user1.isActive = 1 ")
                     .setParameter("employeeId", employeeId)
                     .getResultList();
                    
                     log.info("in getPeers(): peerList.size() = " + peerList.size());
                    
                     ListIterator<User> it = peerList.listIterator();
                     while(it.hasNext()) {
                     User user = (User)it.next();
                     map.put(user.getFirstName()+ " " + user.getLastName(), user.getEmployeeId());
                     }
                    
                     return map;
                     }
                    
                    
                    }