views:

251

answers:

1

I'm using Hibernate 3.5.1, which comes with EHCache 1.5 bundled.

If I want to use the latest EHCache release (2.0.1), is it just a matter of removing the ehcache-1.5.jar from my project, and replacing with ehcache-core-2.0.1.jar? Any issues to be aware of?

Also - is a cache "region" in the Hibernate mapping file that same as a cache "name" in the ehcache configuration xml? What I want to do is define 2 named cache regions - one for read-only reference entities that won't change (lookup lists etc), and one for all other entities. So in ehcache I want to define two elements;

<cache name="readonly"> ... </cache>
<cache name="mutable"> ... </cache>

And then in my Hibernate mapping files, I will specify the cache to be used for each entity:

<hibernate-mapping>
    <class name="lookuplist">
        <cache region="readonly" usage="read-only"/>
        <property> ... </property>
    </class>
</hibernate-mapping>

Will that work? Some of the documentation seems to imply that a separate region/cache gets created for each mapped class...

Thanks.

+2  A: 

If I want to use the latest EHCache release (2.0.1), is it just a matter of removing the ehcache-1.5.jar from my project, and replacing with ehcache-core-2.0.1.jar? Any issues to be aware of?

According to the Ecache documentation about using Ehcache as Hibernate Second Level Cache, you'll have to use ehache-core.jar indeed but also to change Hibernate's configuration.

Also - is a cache "region" in the Hibernate mapping file that same as a cache "name" in the ehcache configuration xml?

Yes. Again, refer to the documentation, this is explained in Configuring ehcache.xml.

Will that work? Some of the documentation seems to imply that a separate region/cache gets created for each mapped class

The documentation doesn't imply, it's written black on white in Cache mappings that this is the default:

region (optional: defaults to the class or collection role name): specifies the 
name of the second level cache region 

Will it work? Technically, yes. Is it a good idea? I'm not sure. It is IMO preferable to have finer grained regions at both Hibernate and Ehcache levels (especially if you plan to use distributed caching and an invalidation strategy, you certainly don't want to invalidate all entities). I would use Hibernate's defaults.

Pascal Thivent