diff --git a/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java b/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java index 81b8619f70df84d82b5b1f9f5746c8f4bf677faf..602b16d6595809bdff7be112defc80fa5fe0d623 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java @@ -290,19 +290,35 @@ public class BusinessGroupRelationDAO { if(groupKeys == null || groupKeys.isEmpty()) { return Collections.emptyList(); } - + StringBuilder sb = new StringBuilder(); sb.append("select rel from ").append(BGRepositoryEntryRelation.class.getName()).append(" as rel ") .append(" where rel.groupKey in (:groupKeys)"); TypedQuery<BGRepositoryEntryRelation> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), BGRepositoryEntryRelation.class); - query.setFirstResult(firstResult); - if(maxResults > 0) { - query.setMaxResults(maxResults); + + if(firstResult >= 0 && maxResults >= 0) { + query.setFirstResult(firstResult); + if(maxResults > 0) { + query.setMaxResults(maxResults); + } + query.setParameter("groupKeys", groupKeys); + return query.getResultList(); } + + List<Long> groupKeyList = new ArrayList<Long>(groupKeys); + List<BGRepositoryEntryRelation> relations = new ArrayList<BGRepositoryEntryRelation>(groupKeys.size()); - query.setParameter("groupKeys", groupKeys); - return query.getResultList(); + int count = 0; + int batch = 500; + do { + int toIndex = Math.min(count + batch, groupKeyList.size()); + List<Long> toLoad = groupKeyList.subList(count, toIndex); + List<BGRepositoryEntryRelation> batchOfRelations = query.setParameter("groupKeys", toLoad).getResultList(); + relations.addAll(batchOfRelations); + count += batch; + } while(count < groupKeyList.size()); + return relations; } public List<BGResourceRelation> findRelations(Collection<Long> groupKeys, int firstResult, int maxResults) {