Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

225
Views
Spring 4 Ehcache 3 Hibernate 5 cache default template setup

My project is on Spring 4.3.4, Hibernate 5.2.4 and Ehcache 3.3

I am looking for a solution with a singular JSR-107 (JCache) CacheManager for the whole the application to provide:

  • Spring caching - with number of explicitly named Caches;
  • Hibernate L2 caching - with the ability to implicitly generate any number of regions (which are in fact the Caches too)

The main concern here is Hibernate. In fact, it is a question of setting a default template for its regions. After the review of a lot of topics I have not discovered a fully suitable solution.

So, if it exists, I'm kindly ask the experts to point to it. A programmatic only way of configuring is highly appreciated (ehcache.xml is unwanted).

Added: (in answer to @Anthony Dahanne): I have already seen the solution in the project you are pointing for before I posted this topic. Even more, this project was the starting point of my investigation week ago.

But that solution is involving the explicit declaration of several named Cache regions not only for Spring, but even for Hibernate, as we can find in the CacheConfiguration#createCacheConfigurations method.

This is inconvinient in a real project wich contains 100500 different Entities, NaturalKeys and so on, which are managed by Hibernate, because for all them it should create appropriate regions on the fly. I distinct the main power of Hibernate's RegionFactory as an ability to do this magic work automaticly. But what we see in the pointed project in the customized JCacheRegionFactory class? The direct ban for it to generate new regions, which is implemented by means of unconditional exception that will be thrown on any attempt to do that (it is even noted with the "...but makes sure all caches are already existing to prevent spontaneous creation of badly configured caches..." comment).

The ideal solution must be able to set up a sole "default template" (on the CacheManager level) just like it works in case of encache.xml (...jcache:defaults default-template="myDefaultTemplate...), ...but without xml.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

There is a JHipster fullstack demo example on ehcache3-samples github repo

This example is based on Spring boot programmatically sets up an ehcache3 cache, exposing it as a JSR-107 CacheManager

This cache is used in conjunction with Hibernate and also independently.

about 4 years ago · Santiago Trujillo Report

0

We never want the default configuration (aka new MutableConfiguration). However, setting a meaningful default is acceptable. So indeed, in your case I would use a customized JCacheRegionFactory.

See this article about it.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!