5 Replies Latest reply on Dec 30, 2005 7:38 PM by epbernard

    EntityManager not injected

    hoetschmann

      Hi.

      Please help:
      I have written a SSB that uses the @PersistenceContext annotation:

      @Stateless
      public class TopicEditAction implements TopicEdit {

      private Topic topic;
      @PersistenceContext(unitName = "pfe")
      EntityManager em;
      ...
      public String add() {
      System.out.println("try adding a topic...");
      if(em==null)System.out.println("em is null");
      em.persist(topic);
      System.out.println("added topic...");
      this.topic=new Topic();
      return "editTopic";
      }


      When the "add" method is executed the output on the console is:

      21:50:19,174 INFO [STDOUT] try adding a topic...
      21:50:19,174 INFO [STDOUT] em is null
      21:50:19,174 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
      javax.faces.FacesException: Error calling action method of component with id _tagId2:_tagId5
      at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:74)
      at javax.faces.component.UICommand.broadcast(UICommand.java:106)
      at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
      at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:164)
      at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:271)
      at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:94)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:122)
      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:81)
      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.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      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:856)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
      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)
      Caused by: javax.faces.el.EvaluationException: /addTopic.xhtml @21,69 action="#{topiceditaction.add}": java.lang.NullPointerException
      at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:73)
      at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
      ... 28 more
      Caused by: java.lang.NullPointerException
      at org.jboss.projects.performance.actions.TopicEditAction.add(TopicEditAction.java:44)
      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:130)
      at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
      at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
      at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:69)
      ... 29 more


      My persistence.xml:

      <entity-manager>
      <name>pfe</name>
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/projectDS</jta-data-source>
      <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
      <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
      </properties>
      </entity-manager>


      I'm using jboss4.0.3SP1 and EJB3.0_RC3. The EAR deploys fine, I think.
      No errors and the schema creates as expected.

      Any suggestion are very appreciated.

      Regards
      Dirk




        • 1. Re: EntityManager not injected
          hoetschmann

          Of course this is the persistence.xml:

          <entity-manager>
          pfe
          org.hibernate.ejb.HibernatePersistence
          <jta-data-source>java:/projectDS</jta-data-source>




          </entity-manager>

          • 2. Re: EntityManager not injected
            hoetschmann

            Sorry...

            <entity-manager>
             <name>pfe</name>
             <provider>org.hibernate.ejb.HibernatePersistence</provider>
             <jta-data-source>java:/projectDS</jta-data-source>
             <properties>
             <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
             <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
             </properties>
            </entity-manager>


            • 3. Re: EntityManager not injected

              Have you tried looking at your JBoss LogFile? It tends to be more verbose than console output by default.

              • 4. Re: EntityManager not injected
                hoetschmann

                Yes, I tried. The only hint is:
                2005-12-05 10:56:25,334 INFO [org.jboss.ejb3.Ejb3Deployment] Create EntityManager with JNDI name: pfe

                Does there has to be some kind of confirmation, like "EntityManager created", or something like that?

                • 5. Re: EntityManager not injected
                  epbernard

                  be sure that add() is part of the public contract (the interface) and that a transaction is started. How do you get your EJB?

                  BTW, I think you should give JBoss Seam a try if not done yet, you're right on the technology target, you'll love it