5 Replies Latest reply on Sep 11, 2008 9:36 AM by mean.meanmachine.gmx.at

    EntityManager-Error:

    mean.meanmachine.gmx.at

      Hello,


      I'am using JBoss/Seam with three DAO-classes. When I login, my AuthenticationBean calls a method in my application tier (findUserByLogin()) which calls a method in my DAO-class (findUserByLogin()).


      All works fine, if I only call my application tier or if I send the database request out of AuthenticationBean or the class from the application tier.


      But if I want to send the request out of the dao, it doesn't work because of my EntityManager (or the instatiation of it). Even if I have this as a method



      @Stateless
      @Local(BenutzerverwaltungDao.class)
      final public class BenutzerverwaltungDaoBean implements BenutzerverwaltungDao {
              @Logger
              Log log;        
              
              @PersistenceContext(name = PERSISTENCE_CONTEXT)
              private EntityManager em;
      
      public User findUserByLogin(...) {
       log.debug(em);
       return User user = new User();
      }



      If I comment the row log.debug(em) or whatever uses em, it works.


      This is my Stack Trace:



      14:18:38,242 ERROR SeamLoginModule Error invoking login method
      javax.el.ELException: javax.ejb.EJBTransactionRolledbackException
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:333)
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:342)
              at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
              at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
              at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
              at org.jboss.seam.core.Expressions$2.invoke(Expressions.java:174)
              at org.jboss.seam.security.jaas.SeamLoginModule.login(SeamLoginModule.java:109)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at javax.security.auth.login.LoginContext.invoke(LoginContext.java:769)
              at javax.security.auth.login.LoginContext.access$000(LoginContext.java:186)
              at javax.security.auth.login.LoginContext$5.run(LoginContext.java:706)
              at java.security.AccessController.doPrivileged(Native Method)
              at javax.security.auth.login.LoginContext.invokeCreatorPriv(LoginContext.java:703)
              at javax.security.auth.login.LoginContext.login(LoginContext.java:575)
              at org.jboss.seam.security.Identity.authenticate(Identity.java:317)
              at org.jboss.seam.security.Identity.authenticate(Identity.java:306)
              at org.jboss.seam.security.Identity.login(Identity.java:235)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329)
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:342)
              at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
              at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
              at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
              at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
              at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
              at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
              at javax.faces.component.UICommand.broadcast(UICommand.java:387)
              at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
              at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
              at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
              at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
              at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
              at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
              at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
              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.web.IdentityFilter.doFilter(IdentityFilter.java:38)
              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:45)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:150)
              at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
              at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:379)
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:506)
              at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
              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.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:73)
              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:182)
              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.Http11AprProcessor.process(Http11AprProcessor.java:856)
              at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:566)
              at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1508)
              at java.lang.Thread.run(Thread.java:619)
      Caused by: javax.ejb.EJBTransactionRolledbackException
              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.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
              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.stateless.StatelessContainer.localInvoke(StatelessContainer.java:240)
              at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:210)
              at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:84)
              at $Proxy247.authenticate(Unknown Source)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              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.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
              at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
              at org.javassist.tmp.java.lang.Object$$javassist18.authenticate(Object$$javassist18.java)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329)
              ... 81 more
      Caused by: java.lang.NullPointerException
              at de.autohaus.benutzerverwaltung.db.BenutzerverwaltungDaoBean.findKundeByLogin(BenutzerverwaltungDaoBean.java:148)
              at de.autohaus.benutzerverwaltung.BenutzerverwaltungBean.findKundeNachLogin(BenutzerverwaltungBean.java:378)
              at de.autohaus.AuthenticatorBean.authenticate(AuthenticatorBean.java:64)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
              at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
              at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
              at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:39)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:31)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
              at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.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.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)
              ... 114 more

      May anyone please help me, how to assign the EntityManager in this class?


      In other classes it works exactly the way I do it in this one.


      Thanks and best wishes,


      Dirk

        • 1. Re: EntityManager-Error:
          thejavafreak

          How does your components.xml and persistence.xml look like?

          • 2. Re: EntityManager-Error:
            mean.meanmachine.gmx.at

            Hi Joshua,


            thanks for your answer! This is my components.xml



            <?xml version="1.0" encoding="UTF-8"?>
            <components xmlns="http://jboss.com/products/seam/components"
                        xmlns:core="http://jboss.com/products/seam/core"
                        xmlns:persistence="http://jboss.com/products/seam/persistence"
                        xmlns:drools="http://jboss.com/products/seam/drools"
                        xmlns:bpm="http://jboss.com/products/seam/bpm"
                        xmlns:security="http://jboss.com/products/seam/security"
                        xmlns:mail="http://jboss.com/products/seam/mail"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:schemaLocation=
                            "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd 
                             http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd 
                             http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
                             http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
                             http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                             http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
                             http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
            
               <core:init debug="@debug@" jndi-pattern="@jndiPattern@"/>
               <!--core:init debug="true" jndi-pattern="autohaus.ear/#{ejbName}/local"/-->
               
                 
               <core:manager concurrent-request-timeout="500" 
                             conversation-timeout="120000" 
                             conversation-id-parameter="cid"
                             parent-conversation-id-parameter="pid"/>
                
               <persistence:managed-persistence-context name="entityManager"
                                                 auto-create="true"
                                  persistence-unit-jndi-name="java:/autohausEntityManagerFactory"/>                          
            
               <drools:rule-base name="securityRules">
                  <drools:rule-files>
                     <value>/security.drl</value>
                  </drools:rule-files>
               </drools:rule-base>
            
               <security:rule-based-permission-resolver security-rules="#{securityRules}"/> 
               
               <security:identity authenticate-method="#{authenticator.authenticate}"/>
               <!--security:identity authenticate-method="#{authenticator.authenticate}" remember-me="true"/-->
               
               <event type="org.jboss.seam.security.notLoggedIn">
                  <action execute="#{redirect.captureCurrentView}"/>
               </event>
               <event type="org.jboss.seam.security.loginSuccessful">
                  <action execute="#{redirect.returnToCapturedView}"/>
               </event>
               
               <mail:mail-session host="localhost" port="2525" username="test" password="test" />
                    
               <!-- For use with jBPM pageflow or process management -->
               <!--  
               <bpm:jbpm>
                  <bpm:process-definitions></bpm:process-definitions>
                  <bpm:pageflow-definitions></bpm:pageflow-definitions>
               </bpm:jbpm>
               -->
                  
            </components>




            This is my persistence.xml




            <?xml version="1.0" encoding="UTF-8"?>
            <!-- Persistence deployment descriptor for dev profile -->
            <persistence xmlns="http://java.sun.com/xml/ns/persistence" 
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                         xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
                         version="1.0">
                         
               <persistence-unit name="autohaus">
                  <provider>org.hibernate.ejb.HibernatePersistence</provider>
                  <jta-data-source>java:/autohausDatasource</jta-data-source>
                  <properties>
                     <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
                     <property name="hibernate.hbm2ddl.auto" value="none"/>
                     <property name="hibernate.show_sql" value="true"/>
                     <property name="hibernate.format_sql" value="true"/>
                     <property name="jboss.entity.manager.factory.jndi.name" value="java:/autohausEntityManagerFactory"/>
                     <property name="hibernate.default_schema" value="public"/>
                  </properties>
               </persistence-unit>
                
            </persistence>




            Thanks a lot and best regards,


            Dirk

            • 3. Re: EntityManager-Error:
              thejavafreak

              Hi Dirk,


              Try changing the declaration of entity manager into this:


              @PersistenceContext(name = PERSISTENCE_CONTEXT)
              private EntityManager entityManager;




              Hopefully it works.

              • 4. Re: EntityManager-Error:
                vladimir.kovalyuk

                Dirk, the stack trace tell you that you have NPE in your findKundleByLogin method. It difficult to guess how the line caused the exception might look like.
                How PERSISTENCE_CONTEXT is defined?

                • 5. Re: EntityManager-Error:
                  mean.meanmachine.gmx.at

                  Morning Joshua and Vladimir,


                  thanks for your fast response!


                  @Joshua: I tried your way, but it didn't work :(


                  @Vladimir: I don't know, if PERSISTENCECONTEXT is the reason for this error. If I just write @PersistenceContext EntityManager am;
                  I get the same error.

                  And in my AuthenticatorBean-Class I just use EntityManager as seen above.

                  Here is the content of this file:

                  package de.autohaus.util;
                  
                  public interface EjbConstants {
                          //-------------------------------------------------------------
                          // JPA
                          String PERSISTENCE_CONTEXT = "autohaus";
                          Long KEINE_ID = null;
                          int ERSTE_VERSION = 0;
                  
                          //-------------------------------------------------------------
                          // Kunde
                          String KUNDE_NACHNAME_PATTERN = "[A-ZÄÖÜ][a-zäöüß]+(-[A-ZÄÖÜ][a-zäöüß]+)?";
                          
                          //-------------------------------------------------------------
                          // Passwort-Verschluesselung
                          String HASH_ALGORITHM = "SHA-1";  // "MD5", "SHA-128", "SHA-256", "SHA-512"
                          String HASH_ENCODING = "base64";
                          String HASH_CHARSET = "UTF-8";
                  }



                  What I'm thinking about is: Is it possible, that I have no settings/permissions to use EntityManager in this package?


                  My AuthenticatorBean.java is in src/ACTION/de/autohaus/AuthenticatorBean.java
                  My BenutzerverwaltungDaoBean.java is in src/MODEL/de/autohaus/BenutzerverwaltungDaoBean.java


                  I dont's know, if this matters... Perhaps I have to tell any xml file to allow files from .../MODEL/... to use EntityManager,..


                  Because the NPE is caused by em, that's null in my mind?!?!


                  Btw: the class of BenutzerverwaltungDaoBean.java I've posted is the complete class, because I commented every other method for testing.


                  Hopefully you have still other ideas what to try.


                  Thank you very much and best regards,


                  Dirk