}
List<Object[]> list = getHibernateTemplate().find("select item.space.id, max(item.sequenceNum) from Item item group by item.space.id");
for(Object[] oa : list) {
Long spaceId = (Long) oa[0];
Long maxSeqNum = (Long) oa[1];
SpaceSequence ss = ssMap.get(spaceId);
logger.info("checking space sequence id: " + spaceId + ", max: " + maxSeqNum + ", next: " + ss.getNextSeqNum());
if(ss.getNextSeqNum() <= maxSeqNum) {
logger.warn("fixing sequence number for space id: " + spaceId
+ ", was: " + ss.getNextSeqNum() + ", should be: " + (maxSeqNum + 1));
ss.setNextSeqNum(maxSeqNum + 1);
getHibernateTemplate().update(ss);
}
}
}