今天项目中遇到hibernate in查询结果集为空的问题.
temp是个map
这段执行后抛出异常.
修改后
String searchModules = "select m from Module m where m.id in (?)";
return find(searchModules, temp.keySet());temp是个map
这段执行后抛出异常.
修改后
Object [] objects = temp.keySet().toArray();
StringBuffer ids = new StringBuffer();
for (Object object : objects) {
ids.append("'").append(object).append("'").append(',');
}
ids.deleteCharAt(ids.length() - 1);
String searchModules = "select m from Module m where m.id in ("+ids.toString()+")";
return find(searchModules);
本文介绍了一种解决Hibernate IN查询返回空结果的方法。通过将Map的key转换为Object数组,再转换成字符串形式拼接到SQL语句中,成功避免了异常并实现了预期的数据查询。
4000

被折叠的 条评论
为什么被折叠?



