Search in sources :

Example 1 with UpdateTimestampsCache

use of org.hibernate.cache.spi.UpdateTimestampsCache in project BroadleafCommerce by BroadleafCommerce.

the class UpdateExecutor method executeTargetedCacheInvalidation.

/**
 * @param em
 * @param entityType
 * @param ids
 */
public static void executeTargetedCacheInvalidation(EntityManager em, Class<?> entityType, List<Long> ids) {
    Session session = em.unwrap(Session.class);
    for (Long id : ids) {
        session.getSessionFactory().getCache().evictEntity(entityType, id);
    }
    // update the timestamp cache for the table so that queries will be refreshed
    ClassMetadata metadata = session.getSessionFactory().getClassMetadata(entityType);
    String tableName = ((AbstractEntityPersister) metadata).getTableName();
    UpdateTimestampsCache timestampsCache = em.unwrap(SessionImplementor.class).getFactory().getUpdateTimestampsCache();
    if (timestampsCache != null) {
        timestampsCache.invalidate(new Serializable[] { tableName });
    }
}
Also used : ClassMetadata(org.hibernate.metadata.ClassMetadata) UpdateTimestampsCache(org.hibernate.cache.spi.UpdateTimestampsCache) AbstractEntityPersister(org.hibernate.persister.entity.AbstractEntityPersister) Session(org.hibernate.Session)

Aggregations

Session (org.hibernate.Session)1 UpdateTimestampsCache (org.hibernate.cache.spi.UpdateTimestampsCache)1 ClassMetadata (org.hibernate.metadata.ClassMetadata)1 AbstractEntityPersister (org.hibernate.persister.entity.AbstractEntityPersister)1