我想在long数据类型字段上编写类似的hql,但是我收到了错误
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long
String hql = "SELECT ... WHERE ID like :searchParam";
Query query = getSession().createQuery(hql);
query.setParameter("searchParam", "%" + searchParam + "%");
data = query.list();
// ID类型为long
答案 0 :(得分:0)
您可以将Long
转换为String
:
String hql = "SELECT ... WHERE cast(ID as String) like :searchParam";