我使用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