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
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.ehcache.org/v3"
xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.8.xsd">
<cache-template name="default">
<expiry>
<ttl unit="seconds">86400</ttl>
</expiry>
<heap unit="entries">10000</heap>
</cache-template>
<cache alias="Category">
<key-type>java.lang.Object</key-type>
<value-type>com.archilleuswebservice.model.documentation.Category</value-type>
<expiry>
<ttl unit="seconds">86400</ttl>
</expiry>
<heap unit="entries">5000</heap>
</cache>
<cache alias="Document">
<key-type>java.lang.Object</key-type>
<value-type>com.archilleuswebservice.model.documentation.Document</value-type>
<expiry>
<ttl unit="seconds">86400</ttl>
</expiry>
<resources>
<heap unit="entries">15000</heap>
</resources>
</cache>
<cache alias="User">
<key-type>java.lang.Object</key-type>
<value-type>com.archilleuswebservice.model.organizationalStructure.User</value-type>
<expiry>
<ttl unit="seconds">86400</ttl>
</expiry>
<resources>
<heap unit="entries">200</heap>
</resources>
</cache>
<cache alias="Company">
<key-type>java.lang.Object</key-type>
<value-type>com.archilleuswebservice.model.organizationalStructure.Company</value-type>
<expiry>
<ttl unit="seconds">86400</ttl>
</expiry>
<resources>
<heap unit="entries">100</heap>
</resources>
</cache>
<cache alias="CompanyRole">
<key-type>java.lang.Object</key-type>
<value-type>com.archilleuswebservice.model.organizationalStructure.CompanyRole</value-type>
<expiry>
<ttl unit="seconds">86400</ttl>
</expiry>
<resources>
<heap unit="entries">200</heap>
</resources>
</cache>
<cache alias="Partner">
<key-type>java.lang.String</key-type>
<value-type>com.archilleuswebservice.model.Partner</value-type>
<expiry>
<ttl unit="seconds">86400</ttl>
</expiry>
<resources>
<heap unit="entries">100</heap>
</resources>
</cache>
</config>
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<CompanyRole> 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.