int evictedEntities = 0;
int evictedCollections = 0;
final Session session = getEntityManager().unwrap(Session.class);
final SessionFactory sessionFactory = session.getSessionFactory();
final Cache cache = sessionFactory.getCache();
for (final Entry<Class<?>, Collection<Serializable>> evictedEntityEntry : entitiesToEvict.entrySet()) {
final Class<?> entityClass = evictedEntityEntry.getKey();
final List<String> collectionRoles = getCollectionRoles(sessionFactory, entityClass);
for (final Serializable id : evictedEntityEntry.getValue()) {
cache.evictEntity(entityClass, id);
evictedEntities++;
for (final String collectionRole : collectionRoles) {
cache.evictCollection(collectionRole, id);
evictedCollections++;
}
}
}