EntityManager remove throws Object:null不是一个已知的实体类型 [英] EntityManager remove throws Object: null is not a known entity type

查看:217
本文介绍了EntityManager remove throws Object:null不是一个已知的实体类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用EntityManager删除数据库中的记录。我正在使用EJB JPA。



它产生错误: Object:null不是一个已知的实体类型。 / p>

这是我的代码:

  public void deleteAppointment(int staffID, int appointmentID){
try {

StaffApointmentsPK staffApointmentsPK = new StaffApointmentsPK();
staffApointmentsPK.setAppointmentId(约会ID);
staffApointmentsPK.setStaffId(staffID);

StaffApointments staffApointments = staffApointmentsFacade.find(staffApointmentsPK);

System.out.println(staff app type+ staffApointments);

em.remove(staffApointments);
em.flush();

但是在我早期的调用下面的函数中,它是非常相似的,但它正在工作。我不明白是什么问题,因为我正在使用 staffApointmentsFacade 搜索该实体。



这是我的其他功能有效:

  public StaffApointments getPatientAppointmentDetails(int appointmentID,int staffID){

StaffApointmentsPK staffApointmentsPK = new StaffApointmentsPK();
staffApointmentsPK.setAppointmentId(约会ID);
staffApointmentsPK.setStaffId(staffID);工作人员

return staffApointments;
}

任何帮助将不胜感激。谢谢



编辑



我通过切换 int staffID,int appointmentID 感谢您的帮助!

解决方案

我通过分别切换int staffID,int appointmentID来解决它。感谢您的帮助@Donovan和@ ma-ve-rick


I am trying to delete a record in the database using EntityManager. I am using EJB JPA.

It produces the error : Object: null is not a known entity type.

Here is my code:

public void deleteAppointment(int staffID, int appointmentID) {
    try {

        StaffApointmentsPK staffApointmentsPK = new StaffApointmentsPK();
        staffApointmentsPK.setAppointmentId(appointmentID);
        staffApointmentsPK.setStaffId(staffID);

        StaffApointments staffApointments = staffApointmentsFacade.find(staffApointmentsPK);

        System.out.println("staff app type " + staffApointments);

        em.remove(staffApointments);
        em.flush();

But in my early call to the function below, it is very similar but it is working. I do not understand what is the problem because I am searching for the entity first using staffApointmentsFacade.

Here is my other function which works:

public StaffApointments getPatientAppointmentDetails(int appointmentID, int staffID) {

        StaffApointmentsPK staffApointmentsPK = new StaffApointmentsPK();
        staffApointmentsPK.setAppointmentId(appointmentID);
        staffApointmentsPK.setStaffId(staffID);
        StaffApointments staffApointments = staffApointmentsFacade.find(staffApointmentsPK);

return staffApointments;
}

Any help would be appreciated. Thanks

EDIT

I solved it by switching the int staffID, int appointmentID respectively. Thanks for all your help!

解决方案

I solved it by switching the int staffID, int appointmentID respectively. Thanks for all your help @Donovan and @ma-ve-rick

这篇关于EntityManager remove throws Object:null不是一个已知的实体类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆