【问题标题】:Eclipselink : Operation not supported: [instantiateForUnitOfWorkValueHolder]Eclipselink:不支持操作:[instantiateForUnitOfWorkValueHolder]
【发布时间】:2017-06-05 09:49:41
【问题描述】:

当我尝试访问实体中存在的方法中延迟加载的@oneToMany 关系属性时出现以下错误。

错误:

Caused by: Exception [EclipseLink-7097] (Eclipse Persistence Services - 2.6.3.v20160428-59c81c5): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Operation not supported: [instantiateForUnitOfWorkValueHolder].
    at org.eclipse.persistence.exceptions.ValidationException.operationNotSupported(ValidationException.java:1496)
    at org.eclipse.persistence.internal.indirection.ProtectedValueHolder.instantiateForUnitOfWorkValueHolder(ProtectedValueHolder.java:61)
    at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiateImpl(UnitOfWorkValueHolder.java:160)
    at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiate(UnitOfWorkValueHolder.java:234)
    at org.eclipse.persistence.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:89)
    at org.eclipse.persistence.indirection.IndirectList.buildDelegate(IndirectList.java:271)
    at org.eclipse.persistence.indirection.IndirectList.getDelegate(IndirectList.java:455)
    at org.eclipse.persistence.indirection.IndirectList$1.<init>(IndirectList.java:597)
    at org.eclipse.persistence.indirection.IndirectList.listIterator(IndirectList.java:596)
    at org.eclipse.persistence.indirection.IndirectList.iterator(IndirectList.java:555)
    at com.order.modelGroupBase.getStatus(GroupBase.java:205)

实体:

@Entity
@Table(name="GROUP")
@Customizer(GroupBaseCustomizer.class)
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@ClassExtractor(GroupClassExtractor.class)
@InstantiationCopyPolicy
@Cacheable
@Cache( alwaysRefresh=true,
refreshOnlyIfNewer=true,
expiry=300000,      
coordinationType = CacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES)
public class GroupBase {

@OneToMany(cascade=CascadeType.ALL, mappedBy="groupBase", targetEntity=Groups.class)
@PrivateOwned
private List groups = new ArrayList<>();

public OrderGroupStatus getStatus() {

//error is at this line when I try to iterate..
for (Iterator itr = getGroups().iterator(); itr.hasNext();) {
    Groups relationship = (Groups) itr.next();
    //some operation..

    }           


}

}

我在 eclipselink 论坛中查看过,但他们没有明确解决这个问题,一些链接说它与编织有关。但在我的应用程序中,我根本没有启用编织,我也不打算这样做.

此代码在没有 JPA 的 Eclipselink 2.3.2 上运行良好。现在我将 Eclipselink 2.6.3 与 JPA 2.0 和 IBM Websphere 8.5.5.8 一起使用。

注意:此问题并非每次都随机发生,而且我观察到,每当创建新对象时。

【问题讨论】:

  • Weaving 可能已被提及,因为它是 1:1 的延迟获取和其他性能优化所必需的。除非您有充分的理由不这样做,否则我会考虑使用它。但是在这种情况下,对于 1:m 和 M:M 的延迟获取不需要编织,因为 EclipseLink 可以注入它自己的列表实现。我以前没有见过这个错误,但快速的解决方法(不推荐)是将映射标记为急切(默认情况下集合是惰性的)。它必须与您的缓存设置有关,不允许对 GroupBase 关系进行获取。 GroupBase 是如何读入的。
  • 另外,如果您现在使用 JPA,2.3.2 中的“工作”是什么?您是否只是进行了直接的 1:1 转换以将 JPA 注释设置为先前的 EclipseLink 设置?如果您在新的 EL 库中“按原样”使用旧的非 JPA 代码,它可以工作吗?组是什么样子的,如果您将日志记录在 Finest 上会记录什么?
  • 嗨@Chris 感谢您调查这个问题!在 2.3.2 中,延迟加载列表的迭代工作正常意味着永远不会抛出异常。当我转换为 JPA 注释并升级到 2.6.3 时,我在延迟加载列表的迭代中遇到了这个问题。我没有使用过 ASIS 旧代码,我已将普通 pojo 类转换为实体。日志没有显示任何有趣的东西,它只是打印这个堆栈跟踪

标签: eclipselink lazy-loading jpa-2.0


【解决方案1】:

经过多次尝试和纠正我的延迟加载设置后,我发现在其他实体的同一实体上使用不同的 fetchType 可能会在 SHARED_CACHE 模式下导致此问题。

@OneToMany(cascade=CascadeType.ALL, mappedBy="groupBase", targetEntity=Groups.class)
@PrivateOwned
private List groups = new ArrayList<>();

默认情况下,@OneToMany 是延迟获取的,但在同一实体“组”的另一个实体中,我已将 fetchType 配置为 EAGER。

当我将两种获取类型都设置为 LAZY 时,此错误停止发生。

【讨论】:

    猜你喜欢
    • 2015-11-27
    • 1970-01-01
    • 1970-01-01
    • 2017-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-15
    相关资源
    最近更新 更多