title: Cant inject Bean class into Restfull WebService (JAX-RS)
body: <p>I'm trying to save data acquired by Rest web service to database using hibernate/persistence.
  In one of my web modules i implemented that service. Database ejb connector is placed in EJB module. They are parts of EAR application.
  Every time when i call pb.addDevice() im getting  java.lang.NullPointerException when puting proper url with params in browser(worked till i wanted to save it to Database). Can't find what is wrong with it. I'm using jboss 6.1.0 Final.</p>
  
  <p>tried answer of <a href="https://stackoverflow.com/questions/11314073/dependency-injection-in-restful-ws">Dependency injection in restful WS</a></p>
  
  <p>and after following it step by step im alse getting nullpointer also</p>
  
  <p>PS. when i changed from </p>
  
  <pre><code>@EJB
  PersistenceBean pb; 
  </code></pre>
  
  <p>to</p>
  
  <pre><code>PersistenceBean pb = new PersistenceBean();
  </code></pre>
  
  <p>i got null pointer on  EntityManager em = emf.createEntityManager(); </p>
  
  <p>code:</p>
  
  <pre><code>@Stateless
  @Path("/RestService")
  public class RestPush  {
  
  @EJB
  PersistenceBean pb; 
  
      @GET
      @Path("/RegisterDevice")
      public void registerDevice(
          @QueryParam("deviceId") String deviceId){
  
          Device d = new Device(true);
          d.setId = deviceId;
          pb.addDevice(d);
      }
  }
  </code></pre>
  
  <p>and EJB class:</p>
  
  <pre><code>@Stateless(mappedName = "PersistenceBean")
  public class PersistenceBean {
  @PersistenceUnit(unitName = "PersistentUnitName")
  EntityManagerFactory emf;
  
  private void persist(Object o, EntityManager entityManager) {
      try {
          entityManager.persist(o);
      } catch (Exception e) {
          logger.severe("Error writing to DB: " + e);
          logger.severe("" + e.fillInStackTrace());
      }
  }
    public void addDevice(Device d) {
      try {
          EntityManager em = emf.createEntityManager(); 
      if (persist(device, em)) {
              logger.info("Device with id : " + device.getId()
                      + " has been added ");
  } else {
              logger.info("Failed to add device with id: " + device.getId());
  } catch (Exception e) {
          logger.severe("PersistenceBean: Could not save device.");
          e.printStackTrace();
  }
  
  }
  </code></pre>
  
  <p>upadate: </p>
  
  <pre><code>EAR
    --EarContent
      --META-INF
         --application.xml
  EJB
    --package in ejbModule
      --PersistenceBean
      --Device
    --META-INF
      --ejb-jar.xml
      --MANIFEST.MF
      --persistence.xml
      --beans.xml
  
  Web
    --package in webModule
      --Rest (auto generated class while creating Webservice)
      --RestPush
    --WebContent
      --META-INF
        --MANIFEST.MF
      --WEB-INF
        --web.xml
        --beans.xml
  </code></pre>
  
  <p>stack trace:</p>
  
  <pre><code>`10:23:28,629 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/RestWeb].[Resteasy]] Servlet.service() for servlet Resteasy threw exception: org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
  at 
  Caused by: java.lang.NullPointerException
  at package.RestPush.registerDevice(RestPush.java:68) [:]
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_27]
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [:1.6.0_27]
  </code></pre>