[hibernate-dev] Natural ID caching bug?

Galder Zamarreño galder at redhat.com
Fri Mar 30 10:01:36 EDT 2012


Hi guys,

I think there's a bug in the Natural ID support impl in Hibernate and wanted to confirm with you:

For entity caching, EntityInsertAction does:

boolean put = persister.getCacheAccessStrategy().insert( ck, cacheEntry, version );			
if ( put && factory.getStatistics().isStatisticsEnabled() ) {
  factory.getStatisticsImplementor().secondLevelCachePut( getPersister().getCacheAccessStrategy().getRegion().getName() );
}

But for natural id caching, insert() return is ignored and only afterInsert()'s result is taken into accound:

NaturalIdXrefDelegate:

case INSERT: { 
   naturalIdCacheAccessStrategy.insert( naturalIdCacheKey, pk );

  ( (EventSource) session() ).getActionQueue().registerProcess(
     new AfterTransactionCompletionProcess() {
	@Override
	public void doAfterTransactionCompletion(boolean success, SessionImplementor session) {
		final boolean put = naturalIdCacheAccessStrategy.afterInsert( naturalIdCacheKey, pk );

		if ( put && justAddedToLocalCache && factory.getStatistics().isStatisticsEnabled() ) {
		   factory.getStatisticsImplementor().naturalIdCachePut(
		naturalIdCacheAccessStrategy.getRegion().getName() );

>From what I've understood, both natural id caching and entity caching should behave in the same way.

Infinispan does not implement afterInsert() because it's not an asynchornous caching strategy, so natural id cache puts on insert are not currently being updated.

Cheers,
--
Galder Zamarreño
Sr. Software Engineer
Infinispan, JBoss Cache





More information about the hibernate-dev mailing list