[英]How to use LIKE in hibernate detached criteria for integer data type?
[英]Hibernate Criteria, Integer and "like"
我正在將我的一些 hql 語句遷移到 Criterias 現在我正在解決一個問題:實體屬性是 Integer 類型,但我需要通配符搜索,所以在 hql 中我做
session.createQuery("from P1 where id like :id").setString("id", "%"+s+"%")
完全沒問題,Hibernate 將 String 轉換為 Integer。
如果我在 Criteria 中嘗試這個,我只會得到一個 ClassCastException
String cannot be cast to Integer
Criteria crit = sessionFactory.getCurrentSession().createCriteria(P1.class);
crit.add(Restrictions.like("id",s)).addOrder(Order.asc("id")).setMaxResults(maxResults);
為什么 Hibernate 對這兩種情況的處理方式不同?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.