0 Replies Latest reply on Jun 18, 2008 3:11 AM by Ramazan Pekin

    EntityManager Injection...

    Ramazan Pekin Newbie

      I wanted the entitymanager have been injected by the container, I cant configure it. After a lot of trial, I decided to ask the question.

      Here is the situation,

      My ear file structure:

      surgeonfish.ear
      |----surgeonfish-ds.xml
      |----META-INF
       |----application.xml
       |----jboss-app.xml
       |----MANIFEST.MF
      |----surgeonfish.jar
       |----com.ao...
       |----META-INF
       |----persistence.xml
       |----MANIFEST.MF
      |----surgeonfish.war
       |----META-INF
       |----MANIFEST.MF
       |----WEB-INF
       |----classes
       |----lib
       |----web.xml
      


      surgeonfish-ds.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <datasources>
       <local-tx-datasource>
       <jndi-name>time_reporting_data_source</jndi-name>
       <connection-url>jdbc:mysql://localhost:3306/timereporting</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <user-name>root</user-name>
       <password>test</password>
       <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
       <metadata>
       <type-mapping>mySQL</type-mapping>
       </metadata>
       </local-tx-datasource>
      </datasources>
      

      application.xml
      <application>
       <display-name>Surgeonfish</display-name>
       <module>
       <web>
       <web-uri>surgeonfish.war</web-uri>
       <context-root>/surgeonfish</context-root>
       </web>
       </module>
       <module>
       <ejb>surgeonfish.jar</ejb>
       </module>
      </application>
      

      jboss-app.xml:
      <jboss-app>
       <module>
       <service>surgeonfish-ds.xml</service>
       </module>
       <loader-repository>
       surgeonfish:archive=surgeonfish.ear
       </loader-repository>
      </jboss-app>
      

      Here my test bean:
      package com.ao...;
      
      
      import javax.ejb.Local;
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.EntityManagerFactory;
      import javax.persistence.Persistence;
      import javax.persistence.PersistenceContext;
      import org.apache.commons.logging.Log;
      import org.apache.commons.logging.LogFactory;
      
      @Stateless
      @Local(value=PrStaffInterface.class)
      public class PrStaffHome {
      
       private static final Log log = LogFactory.getLog(PrStaffHome.class);
      
       @PersistenceContext(unitName="time_report_persistence_context")
       private EntityManager entityManager;
      
       public PrStaff findById(Integer id) {
       log.debug("getting PrStaff instance with id: " + id);
       try {
       /*
       EntityManagerFactory emf = Persistence.createEntityManagerFactory("time_report_persistence_context");
       EntityManager em = emf.createEntityManager();
       PrStaff instance1 = em.find(PrStaff.class, id);
       ---this lines working without any error...---
       */
      
       PrStaff instance = entityManager.find(PrStaff.class, id);->I am taking null pointer exception here...
       System.out.println("instance:"+instance);
       log.debug("get successful");
       return instance;
       } catch (RuntimeException re) {
       log.error("get failed", re);
       throw re;
       }
       }
      }
      

      I cant find reason, why container is not injecting the entity manager. Of course I am missing something but I cant find. Thanks for your helps...

      --EXCEPTION STACKTRACE--
      ------------------------------------------------------------------------
      2008-06-17 17:25:40,256 ERROR [com.ao.utils.pojo.PrStaffHome] get failed
      java.lang.NullPointerException
      at com.ao.utils.pojo.PrStaffHome.findById(PrStaffHome.java:74)
      at com.ao.jdbc.DBSecurity.checkUserPassword(DBSecurity.java:104)
      at com.ao.timereport.servlet.TIMEController.doLogin(TIMEController.java:550)
      at com.ao.timereport.servlet.TIMEController.service(TIMEController.java:58)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      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.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
      at java.lang.Thread.run(Thread.java:595)
      2008-06-17 17:25:40,287 ERROR [STDERR] java.lang.NullPointerException
      2008-06-17 17:25:40,303 ERROR [STDERR] at com.ao.utils.pojo.PrStaffHome.findById(PrStaffHome.java:74)
      2008-06-17 17:25:40,303 ERROR [STDERR] at com.ao.jdbc.DBSecurity.checkUserPassword(DBSecurity.java:104)
      2008-06-17 17:25:40,303 ERROR [STDERR] at com.ao.timereport.servlet.TIMEController.doLogin(TIMEController.java:550)
      2008-06-17 17:25:40,303 ERROR [STDERR] at com.ao.timereport.servlet.TIMEController.service(TIMEController.java:58)
      2008-06-17 17:25:40,303 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      2008-06-17 17:25:40,303 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      2008-06-17 17:25:40,303 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      2008-06-17 17:25:40,303 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      2008-06-17 17:25:40,303 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      2008-06-17 17:25:40,303 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      2008-06-17 17:25:40,318 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      2008-06-17 17:25:40,318 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      2008-06-17 17:25:40,318 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
      2008-06-17 17:25:40,318 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      2008-06-17 17:25:40,318 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      2008-06-17 17:25:40,318 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      2008-06-17 17:25:40,318 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      2008-06-17 17:25:40,318 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      2008-06-17 17:25:40,318 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
      2008-06-17 17:25:40,334 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      2008-06-17 17:25:40,334 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      2008-06-17 17:25:40,334 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
      2008-06-17 17:25:40,334 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)