简体   繁体   中英

Hibernate 2nd level cache + Ehcache issue when trying to get data (List of object) from cache memory

I am able to get the data from cache memory but only for one object by using HibernateTemplate.load(Class entityClass, Serializable id) ,

[2012-03-06 04:34:18,755] [INFO] [com.uprr.app.rim.components.common.service.RIMSpringApplicationContext] [ApplicationContext is set and ready for use for XMF service clients....]
[2012-03-06 04:34:20,255] [WARN] [org.hibernate.mapping.RootClass] [composite-id class does not override equals(): com.uprr.app.rim.components.exinterface.domain.Track]
[2012-03-06 04:34:20,270] [WARN] [org.hibernate.mapping.RootClass] [composite-id class does not override hashCode(): com.uprr.app.rim.components.exinterface.domain.Track]
[2012-03-06 04:34:35,442] [DEBUG] [org.hibernate.cache.CacheFactory] [instantiating cache region: com.uprr.app.rim.components.masters.domain.CommPlaceTypeDO usage strategy: read-only]
[2012-03-06 04:34:35,442] [WARN] [org.hibernate.cache.CacheFactory] [read-only cache configured for mutable class: com.uprr.app.rim.components.masters.domain.CommPlaceTypeDO]
[2012-03-06 04:34:35,646] [DEBUG] [org.hibernate.cache.CacheFactory] [instantiating cache region: com.uprr.app.rim.components.masters.domain.CommPlaceDO usage strategy: read-only]
[2012-03-06 04:34:35,646] [WARN] [org.hibernate.cache.CacheFactory] [read-only cache configured for mutable class: com.uprr.app.rim.components.masters.domain.CommPlaceDO]
[2012-03-06 04:34:36,005] [INFO] [org.hibernate.cache.UpdateTimestampsCache] [starting update timestamps cache at region: org.hibernate.cache.UpdateTimestampsCache]
[2012-03-06 04:34:36,021] [INFO] [org.hibernate.cache.StandardQueryCache] [starting query cache at region: org.hibernate.cache.StandardQueryCache]
[2012-03-06 04:34:36,380] [DEBUG] [org.hibernate.SQL] [select commplacet0_.COM_PLAC_TYPE_ID as COM1_82_, commplacet0_.COM_PLAC_TYPE_CODE as COM2_82_, commplacet0_.COM_PLAC_TYPE_DESC as COM3_82_, commplacet0_.ACT_FLAG as ACT4_82_, commplacet0_.CRTN_USER_ID as CRTN5_82_, commplacet0_.CRTN_DT as CRTN6_82_, commplacet0_.LAST_UPTD_USER_ID as LAST7_82_, commplacet0_.LAST_UPTD_DT as LAST8_82_ from RIM_COM_PLAC_TYPE_MSTR commplacet0_ where commplacet0_.COM_PLAC_TYPE_ID=172 order by commplacet0_.COM_PLAC_TYPE_DESC]
[2012-03-06 04:34:37,052] [DEBUG] [org.hibernate.cache.ReadOnlyCache] [**Caching**: com.uprr.app.rim.components.masters.domain.CommPlaceTypeDO#172]
[2012-03-06 04:34:37,130] [DEBUG] [org.hibernate.cache.ReadOnlyCache] [**Cache hit:** com.uprr.app.rim.components.masters.domain.CommPlaceTypeDO#172]

but when i am trying to get list of object from cache memory by using loadAll (), getHibernateTemplate().find(strQuery) , Query.list() ... these all method will hit database again and trying to caching data again and show alert in logger :

[2012-03-08 06:56:10,050] [DEBUG] [org.hibernate.cache.ReadOnlyCache] [**item already cached:** com.uprr.app.rim.components.masters.domain.CommPlaceTypeDO#**180**]
[2012-03-08 06:56:10,050] [DEBUG] [org.hibernate.cache.ReadOnlyCache] [item already cached: com.uprr.app.rim.components.masters.domain.CommPlaceTypeDO#**169**]
[2012-03-08 06:56:10,050] [DEBUG] [org.hibernate.cache.ReadOnlyCache] [item already cached: com.uprr.app.rim.components.masters.domain.CommPlaceTypeDO#**166**]
[2012-03-08 06:56:10,050] [DEBUG] [org.hibernate.cache.ReadOnlyCache] [item already cached: com.uprr.app.rim.components.masters.domain.CommPlaceTypeDO#**139**]
[2012-03-08 06:56:10,050] [DEBUG] [org.hibernate.cache.ReadOnlyCache] [item already cached: com.uprr.app.rim.components.masters.domain.CommPlaceTypeDO#140]
[2012-03-08 06:56:10,050] [DEBUG] [org.hibernate.cache.ReadOnlyCache] [item already cached: com.uprr.app.rim.components.masters.domain.CommPlaceTypeDO#138]
[2012-03-08 06:56:10,050] [DEBUG] [org.hibernate.cache.ReadOnlyCache] [item already cached: com.uprr.app.rim.components.masters.domain.CommPlaceTypeDO#149]
[2012-03-08 06:56:10,050] [DEBUG] [org.hibernate.cache.ReadOnlyCache] [item already cached: com.uprr.app.rim.components.masters.domain.CommPlaceTypeDO#143]
[2012-03-08 06:56:10,050] [DEBUG] [org.hibernate.cache.ReadOnlyCache] [item already cached: com.uprr.app.rim.components.masters.domain.CommPlaceTypeDO#130]
[2012-03-08 06:56:10,050] [DEBUG] [org.hibernate.cache.ReadOnlyCache] [item already cached: com.uprr.app.rim.components.masters.domain.CommPlaceTypeDO#142]
[2012-03-08 06:56:10,050] [DEBUG] [org.hibernate.cache.ReadOnlyCache] [item already cached: com.uprr.app.rim.components.masters.domain.CommPlaceTypeDO#165]
[2012-03-08 06:56:10,050] [DEBUG] [org.hibernate.cache.ReadOnlyCache] [item already cached: com.uprr.app.rim.components.masters.domain.CommPlaceTypeDO#167]
[2012-03-08 06:56:10,050] [DEBUG] [org.hibernate.cache.ReadOnlyCache] [item already cached: com.uprr.app.rim.components.masters.domain.CommPlaceTypeDO#168]

I'm actually facing the same problem when activating second level cache & trying to cache my criterias.

If I don't set cacheable to true,

Update : I finally found a solution, problem came from my hibernate version. I was in hibernate 3.2. Upgrading to 3.6.9 solved my problem :)

Hope it can help !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM