我正在使用 JBOSS 和 Seam 制作一个 Web 应用程序,但我试图在我的一个类中使用 entityManager 但它为空。我将它连接到外部数据库并在类中打印出 entityManager,它只是说空。当我尝试打开使用该类的网页时,我得到一个空指针异常并且网页说无法实例化 Seam 组件。我在互联网上花了几个小时试图找出问题所在,但我没有成功。任何帮助,将不胜感激。这是该类的代码:
package edu.uwrf.iss.flowershop.session;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.jboss.aop.util.logging.SystemOutLoggerPlugin;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import edu.uwrf.iss.flowershop.entity.FlowerStoreEmployee;
@Stateful
@Scope(ScopeType.SESSION)
@Name("employeePort")
public class EmployeeBean implements EmployeePortal {
//These are the variables to store the employee information
String empID;
String first;
String last;
String ssn;
String phone;
String pay;
String vehicle;
String house;
String street;
String city;
String state;
String zip;
@In (create=true)
private EntityManager entityManager;
//this is the employee list
List<FlowerStoreEmployee> employeeList;
//Constructor
public EmployeeBean(){
employeeList = new ArrayList<FlowerStoreEmployee>();
loadEmployeeList();
}
@SuppressWarnings("unchecked")
public void loadEmployeeList(){
employeeList = new ArrayList<FlowerStoreEmployee>();
entityManager.isOpen();
Query query = entityManager.createQuery("SELECT e FROM FlowerStoreVehicle e");
employeeList.addAll((List<FlowerStoreEmployee>)query.getResultList());
}
//Getters and Setters
public List<FlowerStoreEmployee> getEmployeeList() {
return employeeList;
}
public void setEmployeeList(List<FlowerStoreEmployee> employeeList) {
this.employeeList = employeeList;
}
//used by the add button on the addEmp.xhtml page
public String addEmployee(){
int id = Integer.parseInt(empID);
int soc = Integer.parseInt(ssn);
int paid =Integer.parseInt(pay);
int vehID = Integer.parseInt(vehicle);
int houseID = Integer.parseInt(house);
Integer zCode = Integer.parseInt(zip);
FlowerStoreEmployee n = new FlowerStoreEmployee();
n.setNameFirst(first);
n.setNameLast(last);
n.setPay(pay);
n.setPhone(phone);
n.setSsn(ssn);
employeeList.add(n);
entityManager.persist(n);
return "/employee.xhtml";
}
//used by the remove button on the remEmp.xhtml page
public String remEmployee(){
int searchID = Integer.parseInt(empID);
int emp = 0;
int i = 0;
FlowerStoreEmployee e;
while (emp!= searchID && i<employeeList.size()){
e = employeeList.get(i);
emp = e.getEmployeeId();
}
employeeList.remove(i);
return "/employee.xhtml";
}
//clears the variables used to temporarily store the information entered on the forms
public void clearTemps(){
this.empID = null;
this.first = null;
this.last = null;
this.ssn = null;
this.phone=null;
this.pay = null;
this.vehicle = null;
this.house = null;
this.street=null;
this.city=null;
this.state=null;
this.zip=null;
}
public String createEmp() {
clearTemps();
System.out.println("words");
return "FlowerStore/addEmp.xhtml";
}
//Setters and getters
public String getEmpID() {
return empID;
}
public void setEmpID(String empID) {
this.empID = empID;
}
public String getFirst() {
return first;
}
public void setFirst(String first) {
this.first = first;
}
public String getLast() {
return last;
}
public void setLast(String last) {
this.last = last;
}
public String getSsn() {
return ssn;
}
public void setSsn(String ssn) {
this.ssn = ssn;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPay() {
return pay;
}
public void setPay(String pay) {
this.pay = pay;
}
public String getVehicle() {
return vehicle;
}
public void setVehicle(String vehicle) {
this.vehicle = vehicle;
}
public String getHouse() {
return house;
}
public void setHouse(String house) {
this.house = house;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
/* Seam/Hibernate methods */
@Remove
public void remove() {
}
@Destroy
public void destroy() {
}
}
如果需要任何其他信息,请告诉我。