je qualifierais de « AfterInsert » sur la EntityPersister qui correspond à votre entité depuis lecture/écriture est une stratégie asynchrone concurrency. J'ai reconstitué ceci ensemble après avoir regardé à travers la source d'Hibernate 3.3. Je ne suis pas à 100% que ça va marcher, mais ça me va bien.
EntityPersister persister = ((SessionFactoryImpl) session.getSessionFactory()).getEntityPersister("theNameOfYourEntity");
if (persister.hasCache() &&
!persister.isCacheInvalidationRequired() &&
session.getCacheMode().isPutEnabled()) {
CacheKey ck = new CacheKey(
theEntityToBeCached.getId(),
persister.getIdentifierType(),
persister.getRootEntityName(),
session.getEntityMode(),
session.getFactory()
);
persister.getCacheAccessStrategy().afterInsert(ck, theEntityToBeCached, null);
}
-
/**
* Called after an item has been inserted (after the transaction completes),
* instead of calling release().
* This method is used by "asynchronous" concurrency strategies.
*
* @param key The item key
* @param value The item
* @param version The item's version value
* @return Were the contents of the cache actual changed by this operation?
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.Region}
*/
public boolean afterInsert(Object key, Object value, Object version) throws CacheException;