正在开发使用Netbeans.The实体管理越来越应用程序中的空值的JavaEE应用。 该EM是没有得到注入。 还是我得到一个NullPointerException作为EM越来越在createNamedQuery空值。 任何人都可以请让我知道我失去了什么。
JSP页面级的index.jsp:
<%@page import="managed.userBean" %>
<jsp:useBean id="bean" class="managed.userBean" scope="session" />
.....
<input type="submit" value="Submit" onclick="<jsp:scriptlet> bean.validate();</jsp:scriptlet>" />
userBean.java
package managed;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import session.UserFacade;
@ManagedBean
@SessionScoped
public class userBean implements Serializable {
private String uid, password,role,fname,lname;
private String response="" ;
@EJB
UserFacade userFacade;
....
public String validate() {
System.out.println("in validate going to user facade: " + uid + password);
response = userFacade.validateUser(uid,password);
.....
}
UserFacade.java
package session;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless
public class UserFacade extends AbstractFacade<User> {
@PersistenceContext (unitName = "ExamSysPU")
public EntityManager em;
String role;
@Override
protected EntityManager getEntityManager() {
System.out.println("check if em is open");
return em;
}
public UserFacade() {
super(User.class);
}
public String validateUser(String uid, String password) {
...
List results = em.createNamedQuery("User.findByUid").setParameter("uid", uid).getResultList();
....
}
persistence.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="ExamSysPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>test</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>
谢谢,希尔帕