2 回答

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超8個贊
您沒有在此處發(fā)布錯誤,但是看起來您的Student
bean類沒有默認(rèn)的構(gòu)造函數(shù),該構(gòu)造函數(shù)在執(zhí)行時被調(diào)用
Student studentToUpdate = (Student)newSession.get(Student.class, id);
您可以在將默認(rèn)構(gòu)造函數(shù)與自定義構(gòu)造函數(shù)一起添加到Student類之后嘗試。

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超4個贊
我的刪除方法存在問題:
public static void deleteStudent() throws HibernateException {
Session newSession = factory.openSession();
newSession.beginTransaction();
newSession.createQuery("delete from student s where smarks < 35")
.executeUpdate(); //Used for updates and deletes
newSession.getTransaction().commit();
newSession.close();
}
如果仔細(xì)查看該查詢,則“從學(xué)生中刪除”應(yīng)該是用大寫字母s的“從學(xué)生中刪除”。粗心的錯誤。
添加回答
舉報