依預設,OpenJPA 會停用第二級快取,但 EclipseLink 會啟用第二級快取。 如果要移轉的應用程式不使用快取,則可透過在 2.0 或 2.1 版 persistence.xml 檔中設定下列元素來停用 EclipseLink 中的快取:
<shared-cache-mode>NONE</shared-cache-mode>
對於 1.0 版 persistence.xml 檔,則可透過新增下列內容來停用 EclipseLink 中的快取:
<property name="eclipselink.cache.shared.default" value="false"/>
此規則會偵測 META-INF/persistence.xml 檔中的 <persistence-unit> 配置,其中的現行快取配置會導致在 EclipseLink 中產生不同的預設快取行為。它還會協助您清除 EclipseLink 忽略的 openjpa.DataCache 內容。
為了判斷是否需要進行配置變更,此規則會檢查下列設定的組合:
<shared-cache-mode> 配置元素javax.persistence.sharedCache.mode 持續性內容openjpa.DataCache 持續性內容
如果未指定 openjpa.DataCache 內容或將其設定為 false,並且省略共用快取模式配置或將其設定為 UNSPECIFIED,則必須在 EclipseLink 中變更配置以停用快取。因為 EclipseLink 依預設會啟用快取,所以在 OpenJPA 中將 openjpa.DataCache 內容設定為 true,相當於在 EclipseLink 中不進行共用快取模式設定,或是將 shared-cache-mode 設定為 ALL。如果您手動移除 openjpa.DataCache 配置,請勿繼續執行此規則,因為它會將無配置偵測成行為變更。
此規則的自動修正程式會設定共用快取模式的明確值,以便規則不會繼續標示 persistence-unit。
自動修正程式會評估 openjpa.DataCache 設定,並修改現有的或建立新的
shared-cache-mode 配置或 javax.persistence.sharedCache.mode 內容,讓您的應用程式在 EclipseLink 中具有與 OpenJPA中相同的快取模式行為。
在 OpenJPA 中,如果同時設定規格定義的共用快取值及 openjpa.DataCache 內容,則會使用規格定義的值,除非它是 UNSPECIFIED。
如果此值為 UNSPECIFIED,則會使用 openjpa.DataCache 內容來判斷共用快取模式的正確值。
例如,在下列 persistence.xml 檔中,此規則會標示所有 <persistence-unit> 元素,因為它們需要對快取配置進行變更,以便在 EclipseLink 中維護與 OpenJPA 中相同的快取行為。
| OpenJPA 的 persistence.xml 原始檔 | EclipseLink 對 persistence.xml 檔的自動修正程式變更 |
|---|---|
<persistence>
<persistence-unit name="example1">
...
<shared-cache-mode>UNSPECIFIED</shared-cache-mode>
...
</persistence-unit>
<persistence-unit name="example2">
...
<properties>
<property name="openjpa.DataCache" value="true"/>
</properties>
...
</persistence-unit>
<persistence-unit name="example3">
...
<properties>
<-- no cache properties set -->
</properties>
...
</persistence-unit>
<persistence-unit name="example4">
...
<properties>
<property name="openjpa.DataCache" value="false"/>
<property name="javax.persistence.sharedCache.mode"
value="ALL"/>
</properties>
...
</persistence-unit>
</persistence>
|
<persistence>
<persistence-unit name="example1">
...
<shared-cache-mode>NONE</shared-cache-mode>
...
</persistence-unit>
<persistence-unit name="example2">
...
<shared-cache-mode>ALL</shared-cache-mode>
<properties>
</properties>
...
</persistence-unit>
<persistence-unit name="example3">
...
<shared-cache-mode>NONE</shared-cache-mode>
<properties>
<-- no cache properties set -->
</properties>
...
</persistence-unit>
<persistence-unit name="example4">
...
<properties>
<property name="javax.persistence.sharedCache.mode"
value="ALL"/>
</properties>
...
</persistence-unit>
</persistence>
|
自動修正程式會刪除 openjpa.DataCache 內容 (如果它具有簡式
true 或 false 值。
如果 openjpa.DataCache 內容配置具有其他參數 (如下列範例中所示) ,則自動修正程式會離開該內容,以便您可以判定是否需要任何其他手動變更。
請評估 openjpa.DataCache 內容以進行其他移轉,然後移除此內容,因為 EclipseLink 不會使用它。
<property name="openjpa.DataCache" value="true(Types=com.test.Person;com.test.Employee)"/>
如果 shared-cache-mode 和 javax.persistence.sharedCache.mode 都定義在相同的 persistence-unit中,必要的話,自動修正程式會更新 shared-cache-mode 值,並刪除 javax.persistence.sharedCache.mode 內容。
For JPA 1.0 persistence.xml files, the <shared-cache-mode>
element is not valid. The automated fix evaluates the values of
openjpa.DataCache and javax.persistence.sharedCache.mode persistence properties
and adds an eclipselink.cache.shared.default persistence property when needed.
將自訂配置複製到應用程式建置檔,以啟用修正程式自動化。
如需移轉供應商特定 JPA 配置內容的相關資訊,請參閱下列資源: