问题描述
PatientId的数据类型在实体对象中为BigInteger
private BigInteger patientId;
代码:
@Override
public List<ChatRoomHistory> getLastChatDetails(List<String> patientIds) {
String queryStr = "FROM ChatRoomHistory where type = 'NO' and patientId in :patientIds ORDER BY chatCloseTime DESC";
TypedQuery<ChatRoomHistory> query = sessionFactory.getobject().getCurrentSession().createquery(queryStr,ChatRoomHistory.class);
query.setParameter("patientIds",patientIds);
return query.getResultList();
}
2020-08-16 19:52:27,939 [http-nio-8080-exec-5:] c.t.c.u.e.GlobalExceptionHandler.handleException:243
ERROR - new Global exception handled! Message = java.util.LinkedHashMap cannot be cast to java.math.BigInteger
java.lang.classCastException: java.util.LinkedHashMap cannot be cast to java.math.BigInteger
at org.hibernate.type.descriptor.java.BigIntegerTypeDescriptor.unwrap(BigIntegerTypeDescriptor.java:19)
at org.hibernate.type.descriptor.sql.DecimalTypeDescriptor$1.dobind(DecimalTypeDescriptor.java:47)
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:74)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:280)
解决方法
就像评论中所说的那样,您不能将String列表作为用于数字字段的参数传递。
您应将参数声明为
raise SystemExit(0)
,
您可以通过以下方式更正您的方法:
@Override
public List<ChatRoomHistory> getLastChatDetails(List<BigInteger> patientIds)
{
String hql = "select c from ChatRoomHistory c where c.type = 'NO' and c.patientId in :patientIds ORDER BY c.chatCloseTime DESC";
TypedQuery<ChatRoomHistory> query = sessionFactory.getCurrentSession().createQuery(hql,ChatRoomHistory.class);
query.setParameter("patientIds",patientIds);
return query.getResultList();
}
评论:
-
即使HQL不需要
select_clause
,也要generally good practice包含一个。 -
值列表不能为空; (请参见this)。