We use jpa with Toplink as an implementation and came up with a problem with updating entity lists.
This is basically a 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 change the database by external means, the second call to the findAll () method will return the outdated information, since it reuses the information stored in the cache.
One solution to this problem is to indicate
query.setHint("toplink.refresh", "True");
Thus, we always get updated data. But then we are dependent on Toplink, and we will have to face a problem if we need to change suppliers.
I know that there is an entityManager.refesh () method, but I only saw it in combination with entitytManager.find () to get only one object.
Is there a standard way to get fresh data for a list of objects?