HQL就像查询long数据类型一样

时间:2018-05-24 14:43:44

标签: java hibernate hql

我想在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

1 个答案:

答案 0 :(得分:0)

您可以将Long转换为String

String hql = "SELECT ... WHERE cast(ID as String) like :searchParam";