无法使用JPA创建无状态EJB

时间:2016-06-17 15:28:36

标签: jpa java-ee ejb ejb-3.0 ejb-3.1

我正在尝试使用EJB和JPA向DB插入一些数据。当我执行代码时出现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服务类

@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;
    }



}

1 个答案:

答案 0 :(得分:0)

@PersistenceUnit是原因。我将其更改为@PersistenceContext