मैं EntityPersister कि आपकी संस्था के लिए नक्शे के बाद से पढ़ें/लिखें एक अतुल्यकालिक संगामिति नीति है "afterInsert" कहेंगे। मैंने हाइबरनेट 3.3 स्रोत को देखने के बाद इसे एकसाथ पा लिया। मैं 100% नहीं हूं कि यह काम करेगा, लेकिन यह मेरे लिए अच्छा लग रहा है।
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;
स्रोत
2009-04-01 03:02:01