Hibernate does not issue request cache (recurring reading issue)

I am new to java / spring / hibernate and really felt in love with java after several years of .Net programming.

I am now working on a web application using Spring (MVC, declarative transactions) and Hibernate (3.6, as cache provier - ehCache 2.5). I have some read-only, read-write I would like to cache using the second Hibernate cache and request cache.

everything was fine when I used caching for read-only objects. I added a read-write object and ran performance tests using jMeter. For read and write objects, I ran into the problem of non-repeatability of reading. For instance. There are several parallel threads that read and write to the entity table.

Topic 3 gets search values:

16:34:45,304 DEBUG [http-bio-8080-exec-3] cache.StandardQueryCache:        (StandardQueryCache.java:136) - cached query results were not up to date
16:34:45,304 DEBUG [http-bio-8080-exec-3] hibernate.SQL:(SQLStatementLogger.java:111) - select virtualdev0_.virtual_device_class_id as virtual1_45_,     virtualdev0_.virtual_device_class as virtual2_45_, virtualdev0_.sitebox_id as sitebox3_45_, virtualdev0_.timestamp as timestamp45_ from virtual_device_class virtualdev0_ where     virtualdev0_.sitebox_id=?

He discovers that the cache is not updated and loads objects, adds them to the second-level cache, materializes and returns ... a continuous process from here to 16: 34: 45,826

However, thread 9 deletes one of the objects and updates the second level cache + timestamp:

16:34:45,799 DEBUG [http-bio-8080-exec-9] hibernate.SQL:(SQLStatementLogger.java:111) - delete from virtual_device_class where virtual_device_class_id=?
16:34:45,814 DEBUG [http-bio-8080-exec-9] cache.UpdateTimestampsCache:(UpdateTimestampsCache.java:95) - Invalidating space [virtual_device_class], timestamp: 5466792287494145

Topic 3 continues the household chores and finally adds the query result to the query cache (note that the timestamp will be higher than the timepestamp for the Thread 9 removal action):

16:34:45,826 DEBUG [http-bio-8080-exec-3] cache.StandardQueryCache:(StandardQueryCache.java:96) - caching query results in region: org.hibernate.cache.StandardQueryCache; timestamp=5466792287543296

, , .

16:34:45,852 DEBUG [http-bio-8080-exec-9] cache.UpdateTimestampsCache:(UpdateTimestampsCache.java:122) - [virtual_device_class] last update timestamp: 5466792287494145, result set timestamp: 5466792287543296

, , , .

16:34:45,852 DEBUG [http-bio-8080-exec-9] cache.StandardQueryCache:(StandardQueryCache.java:140) - returning cached query results

, db .

16:34:45,863 DEBUG [http-bio-8080-exec-9] loader.Loader:(Loader.java:2022) - loading entity: [com.test.models.VirtualDeviceClass#0b2f363f-fbb9-4d17-8f86-af86ebb5100c]
16:34:45,873 DEBUG [http-bio-8080-exec-9] hibernate.SQL:(SQLStatementLogger.java:111) - select virtualdev0_.virtual_device_class_id as virtual1_45_0_, virtualdev0_.virtual_device_class as virtual2_45_0_, virtualdev0_.sitebox_id as sitebox3_45_0_, virtualdev0

Load, , db. , . , :

a) trx Repeatable Read in DB ( , , db) b) / c) ( db )

- ?

+3
1

Hibernate 4, .

SessionFactory.getQueryCache(String regionName)

+1

All Articles