Dmitry Bedrin commented on Bug HHH-5690

This issue isn't reproducible neither with CacheConcurrencyStrategy.NONSTRICT_READ_WRITE not with CacheConcurrencyStrategy.READ_WRITE in Hibernate 3.6.0, since org.hibernate.engine.TwoPhaseLoad is more smart in 3.6.0; I was working on 3.3.1.GA previously

Hibernate 3.3.1.GA
boolean put = persister.getCacheAccessStrategy().putFromLoad(
        cacheKey,
        persister.getCacheEntryStructure().structure( entry ),
        session.getTimestamp(),
        version,
        useMinimalPuts( session, entityEntry )
);

if ( put && factory.getStatistics().isStatisticsEnabled() ) {
    factory.getStatisticsImplementor().secondLevelCachePut( persister.getCacheAccessStrategy().getRegion().getName() );
}
Hibernate 3.6.0
// explicit handling of caching for rows just inserted and then somehow forced to be read
// from the database *within the same transaction*.  usually this is done by
// 		1) Session#refresh, or
// 		2) Session#clear + some form of load
//
// we need to be careful not to clobber the lock here in the cache so that it can be rolled back if need be
if ( session.getPersistenceContext().wasInsertedDuringTransaction( persister, id ) ) {
    persister.getCacheAccessStrategy().update(
            cacheKey,
            persister.getCacheEntryStructure().structure( entry ),
            version,
            version
    );
}
else {
    boolean put = persister.getCacheAccessStrategy().putFromLoad(
            cacheKey,
            persister.getCacheEntryStructure().structure( entry ),
            session.getTimestamp(),
            version,
            useMinimalPuts( session, entityEntry )
    );

    if ( put && factory.getStatistics().isStatisticsEnabled() ) {
        factory.getStatisticsImplementor().secondLevelCachePut( persister.getCacheAccessStrategy().getRegion().getName() );
    }
}

It's still a problem for CacheConcurrencyStrategy.TRANSACTIONAL at least when using local transactions (Spring in my case), but I guess it can be solved if using cache as a XA resource in JTA environment (for example ehcache can be configured as XA resource)

Probably this issue can be closed now

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira