String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
Location.class.getName(),
_FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
SQLQuery q = session.createSQLQuery(sql);
q.setFirstResult(0);
q.setMaxResults(2);
if (getDB().isSupportsInlineDistinct()) {
q.addEntity(_FILTER_ENTITY_ALIAS, LocationImpl.class);
}
else {
q.addEntity(_FILTER_ENTITY_TABLE, LocationImpl.class);
}
QueryPos qPos = QueryPos.getInstance(q);
qPos.add(groupId);
if (orderByComparator != null) {
Object[] values = orderByComparator.getOrderByConditionValues(location);
for (Object value : values) {
qPos.add(value);
}
}
List<Location> list = q.list();
if (list.size() == 2) {
return list.get(1);
}
else {