spring-boot - 错误 - 处理了新的全局异常!Message = java.util.LinkedHashMap 不能转换为 java.math.BigInteger
问题描述
PatientId 的 DataType 是实体对象中的 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)
解决方案
您可以通过以下方式更正您的方法:
@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();
}
注释:
推荐阅读
- anylogic - Anylogic如何创建新代理并分配属性?
- python - Flask 无法读取从 html 上传的图像
- jquery - 如何在 HERE 地图中放大和移动地图到相同放大的位置
- firebase - 如何协调 Firebase Auth 令牌刷新与服务器端渲染
- mysql - 通过另一个重复字段自动增加 id
- reactjs - React & Redux - 页面加载时重置错误
- api - 我如何做地方API?
- java - 在 Android 中创建表格视图的问题
- javascript - 如何从嵌入javascript中获取数据
- colors - 在 MIUI 11 / 12 下激活暗模式时的主题问题