依預設,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)"/>
如果在相同 persistence-unit 中同時定義 shared-cache-mode 及 javax.persistence.sharedCache.mode,快速修正程式會在必要時更新 shared-cache-mode 值,並刪除 javax.persistence.sharedCache.mode 內容。
對於 JPA 1.0 persistence.xml 檔,<shared-cache-mode> 元素無效。快速修正程式會評估 openjpa.DataCache 及 javax.persistence.sharedCache.mode 持續性內容的值,並在必要時新增 eclipselink.cache.shared.default 持續性內容。
如需移轉供應商特定 JPA 配置內容的相關資訊,請參閱下列資源: