Can't configure Hibernate 2nd level cache for EhCache 3

183 views Asked by At

I use ehcache.xml for configuration, it works fine but I'm unable to configure settings for Hibernate 2nd level:

My application.ml:

    cache:
        jcache.config: classpath:ehcache.xml
    jpa:
        hibernate:
            ddl-auto: none
            id.new_generator_mappings: true
            cache:
                use_second_level_cache: true
                region.factory_class: jcache
                use_query_cache: true
            javax:
                cache.provider: org.ehcache.jsr107.EhcacheCachingProvider
                cache.uri: classpath:ehcache.xml
            generate_statistics: true

ehcache.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://www.ehcache.org/v3"
        xmlns:jsr107="http://www.ehcache.org/v3/jsr107">
    <service>
        <jsr107:defaults enable-statistics="true" enable-management="true"/>
    </service>
    <cache-template name="default">
        <key-type>java.lang.Object</key-type>
        <value-type>java.lang.Object</value-type>
        <expiry>
            <ttl unit="seconds">
                1
            </ttl>
        </expiry>
        <resources>
            <heap>100</heap>
        </resources>
    </cache-template>
    <cache alias="com.managestudent.model.Religion" uses-template="default">
        <expiry>
            <ttl unit="seconds">5</ttl>
        </expiry>
    </cache>
    <cache alias="religion" uses-template="default">
        <expiry>
            <ttl unit="seconds">5</ttl>
        </expiry>
    </cache>
</config>

Entity:

@Entity
@Table(name = "religion")
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = "religion")
public class Religion {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String religionName;

I tried both region="religion" with <cache alias="religion"/> or use full path name com.managestudent.model.Religion both doesn't work.

Edit: Also the cache gets PUT but no miss reported when I trigger GET /religion/all but not GET /religion/{id} despite having use_query_cache :true

0

There are 0 answers