2nd level cache with multiple sources


I need some help because I have added 2 data sources to my project which actually seemed to be working fine, so I decided to add ehcache as a 2nd level cache and discovered that for the data source which is annotated as @Primary, query caching isn’t working, even though there are hits - it generates selects every time. For the alternative datasource it works just fine. How did I found it out - just removed @Primary annotation from one data source and added to another and the situation got inverted. I guess it has something to do with the SessionFactories, but I don’t know what kind of configuration should be done nor I can find decent info about it.

PS: there are only 2 entities for each data source, very basic, with no relations and @Cacheable + @org.hibernate.annotations.Cache annotations. Also there are 2 repositories which do extend JPARepository and both have @QueryHints annotations in order to cache queries (queries are very simple - looking for an object by single value, which are not the PK). In terms of project Im using ehcache 3+, Hibernate 6+, SpringBoot 3+

Thanks in advance

This is a Hibernate forum, not a Spring forum. Since caching works fine for one persistence unit but not the other, the problem is certainly in your configuration, but you should better ask these questions in Spring forums.

Already did, but no replies so far =( Ok, thanks, will keep investigating.