这是实体
package com.ose.bookstore.model.entity;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
* Entity implementation class for Entity: Login
*
*/
@Entity
public class Login implements Serializable {
private static final long serialVersionUID = 1L;
public Login() {
super();
}
@Id
@GeneratedValue
private int loginId;
private String userEmail;
private String password;
private String secPassword;
public String getUserEmail() {
return userEmail;
}
public void setUserEmail(String userEmail) {
this.userEmail = userEmail;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSecPassword() {
return secPassword;
}
public void setSecPassword(String secPassword) {
this.secPassword = secPassword;
}
public int getLoginId() {
return loginId;
}
public void setLoginId(int loginId) {
this.loginId = loginId;
}
}
这是控制器/测试类
package com.ose.bookstore.model.test;
import javax.ejb.EJB;
import javax.faces.bean.SessionScoped;
import com.ose.bookstore.model.ejb.LoginDao;
import com.ose.bookstore.model.entity.Login;
/**
* @author nishant
*
*/
@SessionScoped
public class LoginTest1 {
@EJB
private static LoginDao loginDao;
public static void main(String[] args) {
// TODO Auto-generated method stub
Login login = new Login();
login.setLoginId(2);
login.setPassword("asdf");
login.setSecPassword("asdfsadF");
login.setUserEmail("email");
loginDao.writeToDb(login);
}
}
这是EJB类
package com.ose.bookstore.model.ejb;
import java.util.List;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import com.ose.bookstore.model.entity.Login;
/**
* @author nishant
*
*/
@Remote
@Stateless
public class LoginDao {
public LoginDao() {
super();
// TODO Auto-generated constructor stub
}
@PersistenceContext
private EntityManager entityManager;
public void writeToDb(Login login){
entityManager.persist(login);
}
}
我收到此错误 loginDao.writeToDb(login);
com.ose.bookstore.model.test.LoginTest1.main 的线程“main”java.lang.NullPointerException 中的异常 LoginTest1 是 Controller/Test 类的类名