OpenJPA 在缺省情况下禁用了二级高速缓存,而 EclipseLink 在缺省情况下则启用了二级高速缓存。 如果要迁移不使用高速缓存的应用程序,可通过在 V2.0 或 V2.1 的 persistence.xml 文件中设置以下元素来禁用 EcipseLink 中的高速缓存:
<shared-cache-mode>NONE</shared-cache-mode>
对于 V1.0 的 persistence.xml 文件,可通过添加以下属性来禁用 EclipseLink 中的高速缓存:
<property name="eclipselink.cache.shared.default" value="false"/>
此规则会检测当前高速缓存配置在 EclipseLink 中产生不同的缺省高速缓存行为的 META-INF/persistence.xml 文件中的 <persistence-unit> 配置。它还可帮助您清除 openjpa.DataCache 属性,EclipseLink 将忽略这些属性。
为确定是否需要进行配置更改,此规则会检查以下设置的组合:
<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 属性。
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 配置属性的更多信息,请参阅以下资源: