Spring Boot 3 + Hibernate 6 + Ehcache 3 problem in creation of caches
04:16 05 Sep 2023

I got weired log when starting exception. I get message from hibernate that cache is created with default configuration and then next log is that ehcache created cache. Do I have 2 caches created or it is bad thing. I am providing below configuration and code:

ehcache.xml which is in my resource folder




    
        
            86400
        
        10000

    

    
        java.lang.Object
        com.archilleuswebservice.model.documentation.Category
        
            86400
        

        5000
    

    
        java.lang.Object
        com.archilleuswebservice.model.documentation.Document
        
            86400
        
        
            15000
        
    

    
        java.lang.Object
        com.archilleuswebservice.model.organizationalStructure.User
        
            86400
        
        
            200
        
    

    
        java.lang.Object
        com.archilleuswebservice.model.organizationalStructure.Company
        
            86400
        
        
            100
        
    

    
        java.lang.Object
        com.archilleuswebservice.model.organizationalStructure.CompanyRole
        
            86400
        
        
            200
        
    

    
        java.lang.String
        com.archilleuswebservice.model.Partner
        
            86400
        
        
            100
        
    


hibernate.properties

hibernate.show_sql=false
hibernate.enable_lazy_load_no_trans=true
hibernate.cache.use_second_level_cache=true
hibernate.cache.region.factory_class=jcache
hibernate.cache.use_query_cache=true
hibernate.javax.cache.uri=classpath:ehcache.xml
hibernate.javax.cache.provider=org.ehcache.jsr107.EhcacheCachingProvider

Example of entity class:

package com.archilleuswebservice.model.organizationalStructure;

import java.io.Serializable;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;

import com.archilleuswebservice.converter.UuidCharConverter;
import jakarta.persistence.*;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(name="company")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Company implements Serializable{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "COMPANY_IDENT")
    private Short id;
    @Column (name = "COMPANY_NAME", nullable = false)
    private String name;
    @Column (name = "COMPANY_LOCALE")
    private Locale locale;
    @Column (name = "COMPANY_EMAIL")
    private String email;
    @Column (name = "COMPANY_ADRESS")
    private String address;
    @Column (name = "COMPANY_PIB", nullable = false)
    private String pib;
    @Column (name = "COMPANY_TOWN")
    private String town;
    /**
     * Maticni broj
     */
    @Column(name = "COMPANY_IDENTIFICATION_NUMBER")
    private String identificationNumber;
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @ManyToMany(fetch = FetchType.LAZY, targetEntity = CompanyRole.class, cascade = CascadeType.ALL)
    @JoinTable(name = "company_role_relation", joinColumns = {@JoinColumn(name = "COMPANY_IDENT")}, inverseJoinColumns = {@JoinColumn(name = "ROLE_IDENT")})
    private Set roles;
    /**
     * Client identification on provider service
     */
    @Convert(converter = UuidCharConverter.class)
    @Column(name = "einvoice_provider_org_uuid")
    private UUID eInvoiceProviderOrganizationUuid;
    @Enumerated(EnumType.STRING)
    @Column(name = "internal_code")
    private InternalCode internalCode;

    ...
}

LOG:

05-09-2023 11:05:11.729 [RMI TCP Connection(2)-127.0.0.1] WARN  org.hibernate.orm.cache.createCache - HHH90001006: Missing cache[com.archilleuswebservice.model.organizationalStructure.Company] was created on-the-fly. The created cache will use a provider-specific default configuration: make sure you defined one. You can disable this warning by setting 'hibernate.javax.cache.missing_cache_strategy' to 'create'.
05-09-2023 11:05:11.731 [RMI TCP Connection(2)-127.0.0.1] INFO  org.ehcache.core.EhcacheManager.createCache - Cache 'com.archilleuswebservice.model.organizationalStructure.Company' created in EhcacheManager.
java caching spring-boot-3 ehcache-3 hibernate-6.x