|
Hi Folks,
tl:dr Second level entity caching behavior is not the same as it was in 1.3.7 and I need help identifying if it is actually a regression or an error on my part. I wen't to configure and verify our second level entity caches today on a 2.0.2 app. Just your basic configuration nothing special (grails create-app Foobar). Default values for the DataSource.groovy configuration with some additional configuration for debugging. hibernate { cache.use_second_level_cache = true cache.use_query_cache = true cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' format_sql = true use_sql_comments = true generate_statistics = true } Then I created a new domain class. Again nothing special and added a cache: 'read-write' mapping configuration to it. It has a single field that is a string and for fun it is unique. Hashcode and equals are implemented for correctness. package me.bendoerr.foobar class Foobar { String cookie static constraints = { cookie unique: true } static mapping = { cache(usage: 'read-write') } boolean equals(final o) { /* removed for brevity */ } int hashCode() { /* removed for brevity*/ } } I then took the same method I use in Grails 1.3.7 to verify caching and implemented it in this project. To my surprise it failed! I spent most of the day debugging and I just do no see the entity cache being hit. Here is the integration test that I shamelessly stole from a guy named Trevor Burnham here http://jira.grails.org/browse/GRAILS-4868. Now it's a little out dated but was working for us in 1.3.7 and I know hibernate and such changed between version so I was hoping that someone could shed some light on the best way to verify second level entity caching, rather than telling me that I may have discovered a regression. You can find my test application at https://github.com/bendoerr/grails-ehcache-entity-cache-issue. It has a branch named grails-1.3.7 that shows the same application and test passing against 1.3.7 configurations. Also of note and evidence that the second level cache is not being hit is the sql logging output. Here is the integration test I am using. import net.sf.ehcache.CacheManager import org.hibernate.SessionFactory import org.hibernate.stat.Statistics class CacheTests extends GroovyTestCase { SessionFactory sessionFactory Statistics statistics void setUp() { new Foobar(cookie: 'Yum').save(failOnError: true, flush: true) CacheManager.instance.clearAll() } void testCacheHits() { 5.times { Thread thread = Thread.start { Foobar.withTransaction { Foobar.get(1) } } while (thread.isAlive()) Thread.sleep(1) } statistics = sessionFactory.statistics assertEquals 1, statistics.secondLevelCacheMissCount assertEquals 4, statistics.secondLevelCacheHitCount } } This test fails with an assertion error that there were actually 5 cache misses. expected:<1> but was:<5> junit.framework.AssertionFailedError: expected:<1> but was:<5> at junit.framework.Assert.fail(Assert.java:50) at junit.framework.Assert.failNotEquals(Assert.java:287) at junit.framework.Assert.assertEquals(Assert.java:67) at junit.framework.Assert.assertEquals(Assert.java:134) at junit.framework.Assert.assertEquals(Assert.java:140) at me.bendoerr.foobar.CacheTests.testCacheHits(CacheTests.groovy:27) Any help would be great. This seems to also be related to http://grails.1312388.n4.nabble.com/second-level-cache-doesn-t-work-in-grails-2-0-td4382978.html Thanks, Ben |
|
We are having the same issue, it seems like it's a regression.
|
|
In reply to this post by bendoerr
Seems, like not many people have verified their 2nd level entity caches since upgrading to 2. I've opened an issue to get this resolved. As far as I can tell, this is a major regression. http://jira.grails.org/browse/GRAILS-9025
-Ben |
|
Administrator
|
The bug is almost certainly in Hibernate 3.6, which means it is beyond
our control Cheers On Fri, Apr 13, 2012 at 2:20 PM, bendoerr <[hidden email]> wrote: > Seems, like not many people have verified their 2nd level entity caches since > upgrading to 2. I've opened an issue to get this resolved. As far as I can > tell, this is a major regression. http://jira.grails.org/browse/GRAILS-9025 > > -Ben > > -- > View this message in context: http://grails.1312388.n4.nabble.com/Second-Level-Entity-Cache-using-default-ehCache-Not-Working-tp4550136p4554575.html > Sent from the Grails - user mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > -- Graeme Rocher Grails Project Lead SpringSource - A Division of VMware http://www.springsource.com --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
On Fri, Apr 13, 2012 at 8:18 AM, Graeme Rocher <[hidden email]> wrote:
The bug is almost certainly in Hibernate 3.6, which means it is beyond That seems like a big leap to make without any attempt to verify it first. Hibernate has FAR wider usage than grails (such that people would have been screaming about broken 2nd level caches almost immediately upon its release) and hibernate 3.6 has been around for a LOT longer than grails 2 (and they seem to do a more comprehensive job of regression test coverage, too, I have to say). It strikes me as very unlikely that such a major regression would be in hibernate 3.6 at this point unless grails 2 is defaulting to a fairly old 3.6 release (in which case the problem is still, ostensibly, with grails).
--sam |
|
In reply to this post by Graeme Rocher-4
Graeme,
I think you were a bit too quick to jump the gun there on blaming Hibernate. I just spent a few more hours investigating* and and I cannot explain it but setting my test to be transactional = false let things work. Do you know why this is? -Ben * Stabbing Blindly in the Dark |
| Powered by Nabble | Edit this page |
