无法使用 JPA 创建无状态 EJB
Could not create stateless EJB with JPA
我正在尝试使用 EJB 和 JPA 将一些数据插入到数据库中。当我执行代码时,出现 serverError: class javax.faces.el.EvaluationException javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
错误。这是我的代码。我通过改变各种东西尝试了很多。发生了什么错误?我认为我的实体管理器初始化有一些错误
DesignationEntity de = new DesignationEntity();
de.setDesignationName(this.designationName);
de.setDesignationDescription(this.designationDescription);
ds.addDesignationDb(de);
EJB 服务class
@Stateless
@LocalBean
public class DesignationService {
@PersistenceUnit(unitName = "ecs2complainmanager")
private EntityManager em;
public DesignationService() {
}
public void addDesignationDb(DesignationEntity de){
em.persist(de);
}
}
Entity class
@Entity
public class DesignationEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private Integer designationId;
private String designationName;
private String designationDescription;
@OneToOne(mappedBy = "designationId")
private UserEntity user;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Integer getDesignationId() {
return designationId;
}
public void setDesignationId(Integer designationId) {
this.designationId = designationId;
}
public String getDesignationName() {
return designationName;
}
public void setDesignationName(String designationName) {
this.designationName = designationName;
}
public String getDesignationDescription() {
return designationDescription;
}
public void setDesignationDescription(String designationDescription) {
this.designationDescription = designationDescription;
}
public UserEntity getUser() {
return user;
}
public void setUser(UserEntity user) {
this.user = user;
}
}
@PersistenceUnit
是原因。我改成@PersistenceContext
后
我正在尝试使用 EJB 和 JPA 将一些数据插入到数据库中。当我执行代码时,出现 serverError: class javax.faces.el.EvaluationException javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
错误。这是我的代码。我通过改变各种东西尝试了很多。发生了什么错误?我认为我的实体管理器初始化有一些错误
DesignationEntity de = new DesignationEntity();
de.setDesignationName(this.designationName);
de.setDesignationDescription(this.designationDescription);
ds.addDesignationDb(de);
EJB 服务class
@Stateless
@LocalBean
public class DesignationService {
@PersistenceUnit(unitName = "ecs2complainmanager")
private EntityManager em;
public DesignationService() {
}
public void addDesignationDb(DesignationEntity de){
em.persist(de);
}
}
Entity class
@Entity
public class DesignationEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private Integer designationId;
private String designationName;
private String designationDescription;
@OneToOne(mappedBy = "designationId")
private UserEntity user;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Integer getDesignationId() {
return designationId;
}
public void setDesignationId(Integer designationId) {
this.designationId = designationId;
}
public String getDesignationName() {
return designationName;
}
public void setDesignationName(String designationName) {
this.designationName = designationName;
}
public String getDesignationDescription() {
return designationDescription;
}
public void setDesignationDescription(String designationDescription) {
this.designationDescription = designationDescription;
}
public UserEntity getUser() {
return user;
}
public void setUser(UserEntity user) {
this.user = user;
}
}
@PersistenceUnit
是原因。我改成@PersistenceContext