亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

錯誤 org.hibernate.exception.SQLGrammarException:

錯誤 org.hibernate.exception.SQLGrammarException:

紅顏莎娜 2022-06-04 11:03:05
我有我正在執行的 hql 查詢,但收到一個我不太了解原因的錯誤。這是我的代碼:@Overridepublic List<StaffRequest> getStaffLeaveRequest(String userID, Date startDate, Date endDate) {    Session currentSession = sessionFactory.getCurrentSession();            List<StaffRequest> results =     currentSession.createQuery("select new com.timesheet_Webservice.CustomEntity.StaffRequest(lr.leave_ID, lr.leave_Employee, concat(s.staff_First_Name, ' ', s.staff_Last_Name), "            + "(lr.leave_Days*8.5), lr.leave_Comments, '1805', concat(pro.project_Pastel_Prefix, ' - ', pro.project_Description), lr.leave_Start, lr.leave_End, lr.leave_IsApproved, "            + "(select lt.leaveType_Description from LeaveType lt where lt.leaveType_ID = lr.leave_Type)) "            + "from Staff s, Project pro, Leave lr "            + "where lr.leave_Employee = s.staff_Code and pro.project_Code = 1805 and lr.leave_Approved = :userID and lr.leave_IsApproved = 0 and s.staff_IsEmployee <> 0 "            + "and lr.leave_Start between :startDate and :endDate "            + "order by concat(s.staff_First_Name, ' ', s.staff_Last_Name)")            .setParameter("userID",userID).setParameter("startDate", startDate).setParameter("endDate", endDate).getResultList();       return results;}嘗試執行時,我在網頁上收到此錯誤:org.hibernate.exception.SQLGrammarException:無法提取 ResultSet還有這個控制臺錯誤:錯誤:您的 SQL 語法有錯誤;檢查與您的 MariaDB 服務器版本相對應的手冊,以在第 1 行的“離開 leave2_ where leave2_.Leave_Employee=staff0_.Staff_Code and project1_.Proj”附近使用正確的語法這似乎表明 where 子句有一些錯誤,但我沒有看到任何特別錯誤的地方。更新: 實體類項目@Entity@Table(name="project")public class Project {    @Id    @GeneratedValue(strategy=GenerationType.IDENTITY)    @Column(name="Project_Code")    public int project_Code;    @Column(name="Project_Customer")    public int project_Customer;    //A lot more attributes...}職員@Entity@Table(name="staff")public class Staff {    @Id    @Column(name="Staff_Code")    public String staff_Code;    ...}
查看完整描述

3 回答

?
守候你守候我

TA貢獻1802條經驗 獲得超10個贊

1)當您使用java.util.DateforLeave.leave_Start時,您應該使用適當的@Temporal值進行注釋:

@Temporal(TemporalType.TIMESTAMP)
@Column(name="Leave_Start")
Date leave_Start;

2)設置查詢日期參數時,嘗試使用:

.setDate("startDate", startDate)

或者

.setParameter("startDate", startDate, TemporalType.TIMESTAMP)


查看完整回答
反對 回復 2022-06-04
?
慕村9548890

TA貢獻1884條經驗 獲得超4個贊

顯然,JPA 遵循變量名稱的一些規則或約定,不接受“_”,并且由于某種原因不接受中間大寫字母......它通過將所有變量更改為小寫字母對我有用



查看完整回答
反對 回復 2022-06-04
?
慕碼人2483693

TA貢獻1860條經驗 獲得超9個贊

好的,經過多次測試,我發現了錯誤的原因。由于某些未知原因,查詢似乎與引用表“離開”的名稱有問題,并且每當我嘗試從中檢索數據時都會產生錯誤。但是,如果我將表重命名為“leaves”之類的簡單名稱,則查詢將成功執行。任何人都可能知道這是為什么?



查看完整回答
反對 回復 2022-06-04
  • 3 回答
  • 0 關注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號