@Override
public List<Position> getLatestPositions() {
EntityManager entityManager = getSessionEntityManager();
synchronized (entityManager) {
List<Position> positions = new LinkedList<Position>();
User user = getSessionUser();
if (user.getDevices() != null && !user.getDevices().isEmpty()) {
TypedQuery<Position> query = entityManager.createQuery(
"SELECT x FROM Position x WHERE x.id IN (" +
"SELECT y.latestPosition FROM Device y WHERE y IN (:devices))", Position.class);
query.setParameter("devices", user.getDevices());
positions.addAll(query.getResultList());
}
return positions;
}
}