HIbernate 3.5.1 - can I just download EHCache 2.0.1?

I am using Hibernate 3.5.1, which comes with EHCache 1.5.

If I want to use the latest version of EHCache (2.0.1), is it just a matter of removing ehcache-1.5.jar from my project and replacing ehcache-core-2.0.1.jar? Any problems you need to know?

Also, is this “cache area” in the Hibernate mapping file the same as the “cache name” in the xh ehcache configuration? What I want to do is define 2 cache areas - one for read-only reference objects that won't change (search lists, etc.), and one for all other objects. So in ehcache I want to define two elements:

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

And then in the Hibernate mapping files, I will specify the cache that will be used for each object:

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

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

Thanks.

+4
source share
2 answers

If I want to use the latest version of EHCache (2.0.1), is it just a matter of removing ehcache-1.5.jar from my project and replacing ehcache-core-2.0.1.jar? Any problems you need to know?

According to Ecache's documentation about using Ehcache as the second level cache in Hibernate , you will need to use ehache-core.jar, but also change the sleep configuration .

Also, is this “cache region” in the Hibernate mapping file the same as the cache “name” in the xh configuration? eccache?

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

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

The documentation does not mean that it is written in black and white in cache mappings , that this is the default value:

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

Will this work? Technically, yes. Is that a good idea? I'm not sure. IMO is preferable to have finer-grained regions at the Hibernate and Ehcache levels (especially if you plan to use distributed caching and a revocation strategy, you certainly do not want to invalidate all entities). I would use the default values ​​for Hibernate.

+2
source

I had the same problem if you use maven.

it is best to prevent hibernate from loading ehcache on its own and not providing your ehcache record.

i.e.

  <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate</artifactId> <version>3.2.6.ga</version> <exclusions> <exclusion> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> </exclusion> </exclusions> </dependency> 

this way it will not load internal ehcache in my case it was version 1.2.3

and then put

  <dependency> <groupId>net.sf</groupId> <artifactId>ehcache-core</artifactId> <version>2.4.2</version> </dependency> 

in your POM.xml

he should work.

0
source

Source: https://habr.com/ru/post/1307857/


All Articles