我有一個最小的Web應用程序,你可以在這裏下載(6KB): http://www.mediafire.com/?6vo1tc141t65r1g無法獲得的EclipseLink二級緩存工作
相關配置爲:
-eclipselink 2.3.2
-server是tomee 1.0(但GlassFish的3.1是相同的)
當我打的頁面,按F5多次刷新:
http://localhost:8080/testCache/jsf/test.xhtml
我看到幾行一樣,在控制檯
[EL精細]:2012-08-29 19:01:30.821 - 的ServerSession(32981564) - 連接(27242067) - 螺紋(線程[HTTP-BIO-8080-EXEC-12,5,主]) - 選擇 ID,任務類型從任務類型
,並通過運行一個嗅探器我看到SQL請求始終發送到服務器。 雖然Eclipselink的2級緩存會返回結果(表中有5行)而不查詢數據庫。 那麼怎麼回事,我該如何激活緩存?
從文件中的某些提取物
的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="xxxPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>microsoft</jta-data-source>
<properties>
<property name="eclipselink.logging.level" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true"/>
</properties>
</persistence-unit>
</persistence>
的EJB執行
/**
* Some useless class required to use JTA transactions
*
* @author Administrator
*
*/
@Stateless
public class Facade {
@PersistenceContext(unitName = "xxxPU")
private EntityManager em;
public List findAll(Class entityClass) {
CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
cq.select(cq.from(entityClass));
return em.createQuery(cq).getResultList();
}
public EntityManager getEntityManager() {
return em;
}
}
實體bean查詢:
@Entity
@Table(name = "tasktype")
public class TaskType {
@Id
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 10)
@Column(name = "tasktype")
private String name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
的感謝!就是它 –
嘗試各種查詢提示組合後,我無法使其工作,當緩存結果時,通過發送緩存列表中的每個項目的單個sql查詢,eclipse鏈接將表現得更糟糕....顯然這篇文章緩存「讀取所有」查詢仍然相關: http://weblogs.java.net/blog/zarar/archive/2010/06/01/integrating-eclipsellink-ehcache-cache-readall-and-native-queries –
re編輯:它的作品,但實體也必須緩存 –