I am using WildFly 8.1, so JPA 2.1 and Hibernate 4.3.5
I want to use a shared cache / second level JPA cache in WildFly
I follow the WildFly documentation: https://docs.jboss.org/author/display/WFLY8/JPA+Reference+Guide#JPAReferenceGuide-UsingtheInfinispansecondlevelcache
here is my persitience.xml:
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="myAppPU" transaction-type="JTA"> <jta-data-source>java:/jdbc/myAppDS</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode> <properties> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> <property name="org.hibernate.flushMode" value="MANUAL"/> <property name="hibernate.cache.use_second_level_cache" value="true"/> </properties> </persistence-unit> </persistence>
I set the hibernate.cache.use_second_level_cache property to true and set the shared-cache mode to ENABLE_SELECTIVE
And the objects (@Entity) that I want to cache are annotated using @Cacheable (true), for example:
@Entity @Cacheable(true) public class Tooltip implements Serializable { @Id private String path ; private String description ; private Boolean rendered ;
But every time I visit the hibernation mode of a web page, you get a lot of choices to get all the objects that I specify as @Cacheable (true), even if I already visit the page (in the same session).
So it looks like the shared / second level cache is not working
Did I miss something?
Thanks hwellmann
I tried putting hibernate.cache.use_query_cache in true in the persitence.xml file
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="myAppPU" transaction-type="JTA"> <jta-data-source>java:/jdbc/myAppDS</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode> <properties> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> <property name="hibernate.cache.use_second_level_cache" value="true"/> <property name="hibernate.cache.use_query_cache" value="true" /> <property name="org.hibernate.flushMode" value="MANUAL"/> </properties> </persistence-unit> </persistence>
and and the prompt in the request that I use
@Entity @NamedQueries({ @NamedQuery(name = "FieldInfos.findAll", query = "SELECT i FROM FieldInfos i", hints = {@QueryHint(name="org.hibernate.cacheable",value="true")}), @NamedQuery(name = "FieldInfos.findByPath", query = "SELECT i FROM FieldInfos i WHERE i.path = :path", hints = {@QueryHint(name="org.hibernate.cacheable",value="true")}) }) @Cacheable(true) public class FieldInfos implements Serializable {
but the problem remains
I am also trying to use the new version of WildFly: 8.2, so Hibernate 4.3.7, but the problem remains too