我使用WildFly 8.1這樣JPA 2.1和Hibernate 4.3.5JPA共享緩存/秒的水平WildFly
我想使用JPA共享緩存/二級緩存WildFly
我按照WildFly文檔:https://docs.jboss.org/author/display/WFLY8/JPA+Reference+Guide#JPAReferenceGuide-UsingtheInfinispansecondlevelcache
這裏是我的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>
我的財產hibernate.cache.use_second_level_cache設置爲true 並設置共享高速緩存模式,以ENABLE_SELECTIVE
和實體(@Entity)我想緩存都標註有@Cacheable(真),這樣的:
@Entity
@Cacheable(true)
public class Tooltip implements Serializable {
@Id
private String path ;
private String description ;
private Boolean rendered ;
//...
}
但每次我訪問網頁hibernate生成了很多select來獲取我已經指示爲@Cacheable(true)的所有實體,即使我已經訪問過該頁面(在同一個會話中)。
如此看來,共享高速緩存/二級緩存不工作
我錯過了什麼?
謝謝hwellmann
我試圖把hibernate.cache.use_query_cache爲True persitence.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="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>
,並與在暗示我使用
查詢@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 {
//...
}
但問題仍然存在
我也嘗試使用新版本的WildFly:8.2以便休眠4.3.7,但問題仍然存在
你解決了你的問題嗎? – 2016-03-13 22:22:55
您是否啓用了統計信息並檢查了WildFly管理控制檯> Runtime> JPA選項卡? – 2017-05-05 07:43:10