7 Replies Latest reply on May 8, 2007 5:35 PM by pmuir

    Help: problem with EntityHome

    qzhengyy

      Hi,

      I am having problem using EntityHome. I have an entity class Foo, follow the Seam documentation in Section 10.2 I define a FooHome class

      public FooHome extends EntityHome<Foo> {
      }
      


      First I get null pointer exception because getEntityManager() returns null. I solve this problem by injecting an entity manager. Now when I call persist() I get the following exception:
      java.lang.NullPointerException
       at com.ericsson.ems.FooHome.persist(FooHome.java:32)
       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:585)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:20)
       at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:57)
       at org.jboss.seam.interceptors.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:47)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.interceptors.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:37)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.interceptors.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:34)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.interceptors.TransactionInterceptor$1.work(TransactionInterceptor.java:32)
       at org.jboss.seam.util.Work.workInTransaction(Work.java:37)
       at org.jboss.seam.interceptors.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:27)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.interceptors.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:27)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103)
       at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:151)
       at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:87)
       at com.ericsson.ems.Eda1500Home_$$_javassist_115.persist(Eda1500Home_$$_javassist_115.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:585)
       at com.sun.el.parser.AstValue.invoke(AstValue.java:174)
       at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:286)
       at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
       at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:69)
       at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
       at javax.faces.component.UICommand.broadcast(UICommand.java:106)
       at org.ajax4jsf.framework.ajax.AjaxViewRoot.processEvents(AjaxViewRoot.java:180)
       at org.ajax4jsf.framework.ajax.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:158)
       at org.ajax4jsf.framework.ajax.AjaxViewRoot.processApplication(AjaxViewRoot.java:329)
       at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:343)
       at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
       at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:60)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
       at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
       at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:79)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
       at org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:84)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:96)
       at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:220)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
       at java.lang.Thread.run(Thread.java:595)
      

      For debugging purpose, I redefined persist method in FooHome and cut and paste the code from EntityHome.persist. The null pointer exception is caused by PersistenceProvide.instance() returns null. Am I missing something? I thought when I use EntityHome I don't need to anything in the XML configuration file.

      Thanks in advance.

      Qing

        • 1. Re: Help: problem with EntityHome
          pmuir

          You've got an NPE in you own code. Fix it. At least show the code that gives the NPE!

          • 2. Re: Help: problem with EntityHome
            qzhengyy

            Here is the code

            public class FooHome extends EntityHome<Foo> {
             @In EntityManage em
             @Transactional
             public String persist() {
             getEntityManager().joinTransaction();
             getEntityManager().persist( getInstance() );
             getEntityManager().flush();
             assignId( PersistenceProvider.instance().getId( getInstance(), getEntityManager() ) ); // This is line 32
             createdMessage();
             return "persisted";
             }
            }
            

            PersistenceProvider.instance() == null

            Thanks

            Qing

            • 3. Re: Help: problem with EntityHome
              pmuir

              Show your components.xml

              • 4. Re: Help: problem with EntityHome
                qzhengyy

                After some debugging I found the cause of the problem my self. In components.xml you need to configure managed-persistence-context and also in persistence.xml you need to set "jboss.entity.manager.factory.jndi.name" property for your database.

                I try to learn seam from the hotel booking example and they are not configured for the example code. Without using EntityHome everything works fine. I ran into this problem when I try to use EntityHome. Maybe the documentation in section 10.2 needs to be updated to include this information. It gave me an impression that if you are using EntityHome and there is no need for xml configuration.

                Really appreciate your help.

                Qing

                • 5. Re: Help: problem with EntityHome
                  pmuir

                   

                  "Reference Manual" wrote:
                  The Seam Application Framework only works with Seam-managed persistence contexts. By default, the components will look for a persistence context named entityManager.


                  • 6. Re: Help: problem with EntityHome
                    qzhengyy

                    That sentence make sense now after all the trouble I have been through. However, for a beginner, that sentence alone probably will not have much help initially. It would be more helpful if it states that you have to this and that or refer to the corresponding sections. Otherwise its become something if you don't know reading it does not help, if you know you don't need to read it.

                    Don't get me wrong, I really apreciate your help and I think Seam is a very good framework. Just want share some of the pains a beginner has.

                    Regards,

                    Qing

                    • 7. Re: Help: problem with EntityHome
                      pmuir

                      I updated the SeamProblemsFAQ to cover this in more depth - a more suitable place I think.