2014-06-28 44 views
0

我想使用EntityManager刪除數據庫中的記錄。我正在使用EJB JPA。EntityManager刪除拋出對象:null不是一個已知的實體類型

它會產生錯誤:Object: null is not a known entity type

這裏是我的代碼:

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(); 

但在我早期的調用下面的函數,它是非常相似,但它工作。我不明白是什麼問題,因爲我正在使用staffApointmentsFacade首先搜索實體。

這裏是我的其他功能,工作原理:

public StaffApointments getPatientAppointmentDetails(int appointmentID, int staffID) { 

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

return staffApointments; 
} 

任何幫助,將不勝感激。由於

編輯

我分別切換int staffID, int appointmentID解決它。感謝你的幫助!

+2

什麼是System.out.println(「staff app type」+ staffApointments)的輸出?它看起來像staffApointments爲空... – Puce

+0

@Puce是的。它輸出staffApointments爲nulll。我不知道爲什麼它會輸出null,因爲「getPatientAppointmentDetails」在我嘗試輸出System.out.println(「staff app type」+ staffApointments)時起作用 – MLDS

+1

你確定你確實調用了'deleteAppointment'函數嗎?我注意到,與「getPatientAppointmentDetails」進行比較時,提供的ID在方法簽名中混合使用。 –

回答

0

我通過分別切換int staffID,int appointID來解決它。感謝您的所有幫助@Donovan和@ ma-ve-rick

相關問題