通过服务类访问EJB

时间:2013-01-07 12:49:14

标签: java ejb persistence

我需要访问EJB来添加/删除数据库中的对象,目前我的带注释的控制器(使用spring)调用服务类,而服务类又调用Facade来解决我的数据库请求。
我得到了这个例外:

警告:StandardWrapperValve [dispatcher]:PWC1406:Servlet调度程序的Servlet.service()引发了异常 显示java.lang.NullPointerException     在br.com.CadmusWeb.service.ClienteService.novoCliente(ClienteService.java:21)     在br.com.CadmusWeb.controller.LoginController.clienteNovo(LoginController.java:100) (标有>>异常列出的行)

我是EJB

的新手

我的控制器:

@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"));

    >>cliServ.newClient(cli);

    return new ModelAndView("clientMenuNew");
}   

服务类

public class ClientService {

@EJB
  private ClientFacade clientFacade;

  public void novoClient(Client cli){
  >>clientFacade.create(cli);
  }

  public void deleteClient(Client cli){
    clientFacade.remove(cli);
  }
} 

ClientFacade

@Stateless
public class ClientFacade extends AbstractFacade<Client> {
@PersistenceContext(unitName = "WebProjectPU")
private EntityManager em;

@Override
protected EntityManager getEntityManager() {
    return em;
}

public ClientFacade() {
    super(Client.class);
}

}

0 个答案:

没有答案