Liferay with JBoss Cache
November 27, 2009 8:42 PM
Last days I'm working on Liferay based project with JBossAS 5.1 used
as server.
Since during redeploy I've met strange problems from ehcache used as
second-level cache (in general it works well, but looks like during
redeploy it cannot find some classes/methods from Hibernate) I've
decided to try to use JBoss Cache as second-level cache for hibernate.
OK, first try is failed - I did not managed to make it working - but
I hope I will able soon - any comments or suggestions will be very helpful!
Until now - to make Liferay to use JBoss Cache - I changed
portal.properties (in my case, since I'm working in ext-environment
I've edited portal-ext.properties) to contains:
hibernate.cache.provider_class=
hibernate.cache.region.factory_class=org.hibernate.cache.jbc2.JndiMultiplexedJBossCacheRegionFactory
hibernate.cache.region.jbc2.cachefactory=java:CacheManager
hibernate.cache.region.jbc2.cfg.entity=mvcc-entity
hibernate.cache.region.jbc2.cfg.query=local-query
hibernate.cache.region_prefix=tempdb
Don't have clear ideas about all these configurations - just got it
from Hibernate + JBoss Cache tutorial.
His settings said to use cache from JBoss service
CacheManager (got from JNDI) - what is nice -
it is possible to configure cache to work (for example) clustering on
server-level, and use this cache in different applications.
Also - note:
- JBoss Cache and CacheManager service is included (by default) only
into all configuration, so, you need run JBoss in
this configuration and deploy Liferay into it
- If you are using ant-script to clean/deploy ext-environment -
please be sure it is not removed libraries from
<jboss>/server/all/lib folder - if removed - please return
them back
Why it is failed?
So, as I told - in my case it is not working. During starting Liferay
I've got exception:
Caused by: org.hibernate.cache.CacheException: unsupported access type [read-write]
at org.hibernate.cache.jbc2.entity.EntityRegionImpl.buildAccessStrategy(EntityRegionImpl.java:66)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:256)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
I've checked sources - yes, this class supports only
AccessType.READ_ONLY & AccessType.TRANSACTIONAL. There is TODO to
add support for READ_WRITE - but - looks like it is not implemented yet.
As I checked - for all classes in liferay mappings - read-write
strategy is used for class-cache, so, it is failed to use JBoss Cache...
How to fix?
I do not have clear idea for now. I see few steps:
- Understand why read-write is not supported - and is it difficult
to add such support?
- use wrapper - to convert requested read-write access-type into
read-only - but - it need to be investigated - probably such change
of strategy will produce ome problems during Liferay working - or
big performance degradation.
OK, at least for now it is not top priority for me - so, leave it for
some future time.