Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java OpenJPA和二级缓存(Ehcache)_Java_Jpa_Ehcache_Openjpa - Fatal编程技术网

Java OpenJPA和二级缓存(Ehcache)

Java OpenJPA和二级缓存(Ehcache),java,jpa,ehcache,openjpa,Java,Jpa,Ehcache,Openjpa,我想在我的项目中为JPA添加二级缓存。 我添加了ehcache-core(net.sf.ehcache),添加了ehcache-openjpa-0.2.0.jar。 我有一个实体: @Entity public class People{ @Id private int ID; private String NAME; ...setter and getter... } 在我的dao类中,我有一个方法: public List<People> getAllCountry()

我想在我的项目中为JPA添加二级缓存。
我添加了ehcache-core(net.sf.ehcache),添加了ehcache-openjpa-0.2.0.jar。 我有一个实体:

@Entity
public class People{
 @Id
 private int ID;

 private String NAME;
...setter and getter...
}
在我的dao类中,我有一个方法:

public List<People> getAllCountry(){
 Query query = getEntityManager().createQuery("SELECT p FROM People p");
 return query.getResultList();
}
公共列表getAllCountry(){
Query Query=getEntityManager();
返回query.getResultList();
}
我添加了ehcache.xml:

<ehcache> 
    <defaultCache 
          maxElementsInMemory="1000" 
          eternal="false" 
          timeToIdleSeconds="300" 
          timeToLiveSeconds="600" 
          overflowToDisk="false" 
          memoryStoreEvictionPolicy="LRU" 
          /> 

    <!-- OpenJPA data cache --> 
    <cache name="openjpa" 
                 maxElementsInMemory="5000" 
                 eternal="false" 
                 timeToIdleSeconds="300" 
                 timeToLiveSeconds="600" 
                 overflowToDisk="false" 
                 memoryStoreEvictionPolicy="LRU" 
          /> 

    <!-- OpenJPA query cache --> 
    <cache name="openjpa-querycache" 
           maxElementsInMemory="1000" 
           eternal="false" 
           timeToIdleSeconds="300" 
           timeToLiveSeconds="600" 
           overflowToDisk="false" 
           memoryStoreEvictionPolicy="LRU" 
          /> 
</ehcache> 

在persistence.xml中,我添加了:

<property name="openjpa.QueryCache" value="ehcache"/> 
<property name="openjpa.DataCacheManager" value="ehcache"/> 

但随后我运行查询,然后得到消息:

查询“.”已从缓存中删除,并被临时排除。Quer“.”未缓存,因为其结果不是通过执行select语句获得的。如果查询是在内存中计算的,则可能发生这种情况。结果由org.apache.openjpa.datacache.QueryCacheStoreQuery$CachingResultObjectProvider提供

我如何解决这个问题