title: Accessing EJB through service class
body: <p>I need to access an EJB to add/delete objects on a database, currently my annotated controller (using spring) calls the service class that in turn calls the facade to do solve my database requests.<br>
  I am getting this exception:  </p>
  
  <p>WARNING: StandardWrapperValve[dispatcher]: PWC1406: Servlet.service() for servlet dispatcher threw exception
  java.lang.NullPointerException
      at br.com.CadmusWeb.service.ClienteService.novoCliente(ClienteService.java:21)
      at br.com.CadmusWeb.controller.LoginController.clienteNovo(LoginController.java:100)
  (Marked with >> the lines the exception póints out)</p>
  
  <p>I am new to the usage of EJB</p>
  
  <p>My controller:</p>
  
  <pre><code>@Controller
  public class LoginController {
  
    private ClientService cliServ;
  
    public LoginController() {
      this.cliServ = new ClientService();
    }
  
  @RequestMapping("clientMenu/clientNew.html")
  public ModelAndView clientNew(HttpServletRequest request) {
      Client cli = new Client();
      cli.setName((String) request.getAttribute("clientName"));
  
      &gt;&gt;cliServ.newClient(cli);
  
      return new ModelAndView("clientMenuNew");
  }   
  </code></pre>
  
  <p>The service class</p>
  
  <pre><code>public class ClientService {
  
  @EJB
    private ClientFacade clientFacade;
  
    public void novoClient(Client cli){
    &gt;&gt;clientFacade.create(cli);
    }
  
    public void deleteClient(Client cli){
      clientFacade.remove(cli);
    }
  } 
  </code></pre>
  
  <p>ClientFacade</p>
  
  <pre><code>@Stateless
  public class ClientFacade extends AbstractFacade&lt;Client&gt; {
  @PersistenceContext(unitName = "WebProjectPU")
  private EntityManager em;
  
  @Override
  protected EntityManager getEntityManager() {
      return em;
  }
  
  public ClientFacade() {
      super(Client.class);
  }
  
  }
  </code></pre>