Pages

Thursday, June 11, 2015

Ehcache Issue : Element <cache> does not allow attribute "maxEntriesLocalHeap"

When using Ehcache as Hibernate second level cache provider, You may face the org.xml.sax.SAXException like this:

Caused by: org.xml.sax.SAXException: null:25: Element <cache> does not allow attribute "maxEntriesLocalHeap".

Reason

This is because in “maxEntriesLocalHeap” is used in ehcahe configuration file ehcache.xml. “maxEntriesLocalHeap” is introducted to ehcache from 2.5, so if the actually ehcache-core version in you project is less then 2.5, the excpetion above comes out.

Unfortunately, Hibernate 4.3 release still uses ehcache 2.4.3. So if the project pom.xml just like this, the exception occures.

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>4.3.4.Final</version>
</dependency>

image


Solution


To solve this, just add explicit dependency to you project.

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>4.3.4.Final</version>
</dependency>

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

Now the dependency looks like this, the SAXException is gone.


image

No comments:

Post a Comment