4

I've been trying to find a way to implement second-level caching using Spring Boot 3 + Ehcache 3 + Hibernate 6 but it's been an unsuccessful ride so far.

I tried looking it up on the internet but no tutorial exists. Maybe I'm the first one?

Edit: Basically the issue is with dependencies. Spring Boot 3 needs Jakarta but Ehcache is using Javax. There are also lots of unavailable dependencies from EhCache 3. Forcing everything together just does not work.

Can anyone help?

HyperX Pro
  • 158
  • 2
  • 9
  • what have you tried? Asking for finding a tutorial / documentation is an off-topic question for stackoverflow. – M. Deinum Mar 13 '23 at 09:11
  • I'm sort of looking for right dependencies as I can't find any which work with Jakarta (Spring Boot 3). – HyperX Pro Mar 13 '23 at 09:24
  • They don't need to. I suggest the hibernat documentation. Use the JCache implementation and EhCache as the implementation. This has nothing to do with Jakarta as the JCache API isn't part of JakartaEE but still part of the regular Oracle packages. – M. Deinum Mar 13 '23 at 09:26
  • I tried but it cannot find `javax.cache` classes even though I added the dependency for it. – HyperX Pro Mar 13 '23 at 09:28
  • Why would you need the classes? You only need the configuration and the hibernate-jcache dependency (which should pull in the proper jcache stuff) and a proper version of ehcache. – M. Deinum Mar 13 '23 at 09:30

2 Answers2

7

Starting with Ehcache version 3.10 there's a Jakarta EE version which you can declare like this in Spring Boot 3.x projects:

<dependency>
  <groupId>org.ehcache</groupId>
  <artifactId>ehcache</artifactId>
  <classifier>jakarta</classifier>
</dependency>

See https://github.com/ehcache/ehcache3/releases/tag/v3.10.0.

Maarten1985
  • 123
  • 6
0

Okay, So I ended up using Spring Boot BOM to fix the missing dependency by Hibernate JCache.

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>3.0.4</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

Now use Hibernate Jcache with Ehcache3.

        <dependency>
            <groupId>org.hibernate.orm</groupId>
            <artifactId>hibernate-jcache</artifactId>
        </dependency>

        <dependency>
            <groupId>org.ehcache</groupId>
            <artifactId>ehcache</artifactId>
            <version>3.10.8</version>
        </dependency>
HyperX Pro
  • 158
  • 2
  • 9