/** * * @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}); } }
public void afterTransactionCompletion(boolean success) { for ( AfterTransactionCompletionProcess process : processes ) { try { process.doAfterTransactionCompletion( success, session ); } catch ( CacheException ce ) { LOG.unableToReleaseCacheLock( ce ); // continue loop } catch ( Exception e ) { throw new AssertionFailure( "Exception releasing cache locks", e ); } } processes.clear(); if ( session.getFactory().getSettings().isQueryCacheEnabled() ) { session.getFactory().getUpdateTimestampsCache().invalidate( querySpacesToInvalidate.toArray( new String[ querySpacesToInvalidate.size()] ) ); } querySpacesToInvalidate.clear(); } }
public void afterTransactionCompletion(boolean success) { for ( AfterTransactionCompletionProcess process : processes ) { try { process.doAfterTransactionCompletion( success, session ); } catch ( CacheException ce ) { LOG.unableToReleaseCacheLock( ce ); // continue loop } catch ( Exception e ) { throw new AssertionFailure( "Exception releasing cache locks", e ); } } processes.clear(); if ( session.getFactory().getSettings().isQueryCacheEnabled() ) { session.getFactory().getUpdateTimestampsCache().invalidate( querySpacesToInvalidate.toArray( new String[ querySpacesToInvalidate.size()] ) ); } querySpacesToInvalidate.clear(); } }