エンティティはこちら
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 での java.lang.NullPointerException LoginTest1 は Controller/Test クラスのクラス名です