We're using jpa with Toplink as an implementation and came up with a problem about refreshing lists of entities.
Basically this is the scenario:
private List<Entity> findAll()
{
final String sql = "SELECT e from " + anEntityClass.getSimpleName() + " e";
final Query query = itsManager.createQuery(sql);
List<Entity> result = query.getResultList();
return result;
}
But if we modify the database by external means, a second call to findAll() method will return outdated information because it reuses the info stored in cache.
One solution to this problem is to specify
query.setHint("toplink.refresh", "True");
So we always get refreshed data. But then we are depending on Toplink and we would face a problem if we need to change providers.
I know that there's an entityManager.refesh() method but I've only seen it in combination with entitytManager.find() to get only one entity.
Is there any standard way to get fresh data for a list of entities?