1. 程式人生 > >org.hibernate.QueryException: could not resolve property的解決辦法

org.hibernate.QueryException: could not resolve property的解決辦法

could not resolve property: cust_name of: domain.Customer
could not resolve property: cust_name of: domain.Customer; nested exception is org.hibernate.QueryException: could not resolve property: cust_name of: domain.Customer

首先看看報的錯。
重點在於“cust_name”這是資料庫中的一個欄位,報的錯是無法解析這個欄位,Idea能自動生成持久化類和對應的配置檔案,所以先排除配置檔案出錯。進入配置檔案會發現在這裡插入圖片描述

它自動去除了下劃線。因此如下圖所寫的為錯誤示範,也就是本次報錯的原因,應該將配置屬性名和orm對映名稱相同
在這裡插入圖片描述

下劃線去掉使用Customer類中的屬性名就正確了。