我试图通过他们的 uuid 从数据库中获取一组值。当我使用 hibernate Restrictions.in(String field, Collection collection) 尝试这个时,它只返回 10 个结果。
public List<Player> getPlayersByUuid(List<String> playerUuids) {
DetachedCriteria criteria = DetachedCriteria.forClass(Player.class);
criteria.add(Restrictions.in("playerUuid", playerUuids));
return hibernateTemplate.findByCriteria(criteria);
}
但是,如果我创建一个列表,通过单独的操作获取每个项目,我会得到所有项目。
public List<Player> getPlayersByUuid(List<String> playerUuids) {
List<Player> players = new ArrayList<Player>();
for (String playerUuid : playerUuids) {
players.add(getPlayerByUuid(playerUuid));
}
return players;
}
public Player getPlayerByUuid(String playerUuid){
DetachedCriteria criteria = DetachedCriteria.forClass(Player.class);
criteria.add(Restrictions.eq("playerUuid", playerUuid));
List<Player> players = hibernateTemplate.findByCriteria(criteria);
if(players.size() == 0) {
return null;
} else if(players.size() == 1) {
return players.get(0);
} else {
//return exception
return null;
}
}
限制有什么限制吗?如果没有,我做错了吗?
谢谢