-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem with read only cache in hibernate 4.1.4
PostPosted: Tue Jun 26, 2012 6:17 am 
Newbie

Joined: Tue Jun 26, 2012 5:51 am
Posts: 1
Hello. It will be nice if someone helps me.

After upgrading to the latest hibernate version (4.1.4) from the version 3.5.6 some unit tests started to fail because of the following exception:
Code:
java.lang.UnsupportedOperationException: Can't write to a readonly object


In a unit test I just persist some entities using entityManager.persist and then load them using entityManager.find. These entities are configured to use read-only second level cache (ehcache).
Simple example:
Code:
Brand brand = new Brand();
entityManager.persist(brand);
entityManager.flush();
entityManager.clear();

  Brand brandFound= entityManager.find(Brand.class, brand.getId());
  assertEquals(brand, brandFound);


The problem that the org.hibernate.engine.internal.TwoPhaseLoad class was updated in a scope of the https://hibernate.onjira.com/browse/HHH-5490:
Code:
// 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
            );
         }

As a unit test runs in one transaction the persister.getCacheAccessStrategy().update line is executed what leads to the described exception because the ReadOnlyEhcacheEntityRegionAccessStrategy is used for an entity.
Earlier in the hibernate 3.5.6 the putFromLoad method was used and everything worked perfectly.

So I'm just not sure what to do. Is this really a correct behavior? Isn't it strange that when you're reading entity using entityManager.find you should make sure that it hasn't been inserted in a same transaction (if we use read only cache for it). As it's still allowed to persist new entities configured with second level read-only cache - this seems to be a bug.

Thanks in advance for any response.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.