---
title: "OPenJPA2.0疑点_2"
author: "ninggy"
date: "2011-05-26T16:20:02Z"
tags: ["Cache", "XML"]
categories: ["编程语言"]
slug: "openjpa2-0-2"
draft: false
lastmod: "2011-05-26T16:20:02Z"
id: 1059819
url: "https://ninggy.iteye.com/blog/1059819"
---

OPenJPA配置时候采用缓存之后**“级联删除**”等操作不能成功，所以在操作之前请清空缓存：

 

```
    EntityManagerFactory emf = tftpDAO.getEntityManagerFactory();
    OpenJPAEntityManagerFactory oemf = OpenJPAPersistence.cast(emf);
    Cache qcache = oemf.getCache();
    qcache.evictAll();
```

 

 如果采用缓存又不想添加上面的代码就在数据库中去设置级联操作了，呵呵![](/images/smiles/icon_smile.gif)。

 

 persistence.xml设置缓存代码：

 

```
      <!-- 启用缓存，并且设置缓存的容量为5000，并且禁用软引用容量 -->
      <property name="openjpa.DataCache" value="true(CacheSize=5000, SoftReferenceSize=100)" />
      <!-- 启用查询结果缓存，缓存的容量为1000，并且软引用的容量为100 -->
      <property name="openjpa.QueryCache" value="true(CacheSize=5000, SoftReferenceSize=100)" />
```