解決欄位名帶底線在Hibernate映射問題

來源:互聯網
上載者:User

  昨天寫程式的過程中遇到了一個莫名其妙的問題,用hql語句去查詢的時候總是會報錯,錯誤資訊:attrtype標識符無效,一般來說這種問題最常見的是欄位名稱對應錯誤,所以我去檢查了這個檔案---TblAttr.hbm.xml,裡面對應正確。我的hql="select tblattr from TblAttr as tblattr where punid='"+punid+"' and attrtype like ''%"+attrtype+"%";

而這句:hql="select tblattr from TblAttr as tblattr where punid='"+punid+"'";執行沒有問題,經過測試發現是欄位名稱帶有底線導致Hibernate映射的時候無法識別。解決這個問題也挺簡單的,只要後面的條件部分給它一個別名就可以了。

修改後的hql語句:

hql="select tblattr from TblAttr as tblattr where punid='"+punid+"' and tblattr.attrtype like ''%"+attrtype+"%";

紅色部分就是在欄位名稱前面加一個別名就可以了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.