当我尝试在实体中存在的方法中访问Lazy加载的@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结合使用。
注意:此问题不是每次都是随机发生的,也是在我创建新对象的时候发生的。
答案 0 :(得分:0)
经过多次命中和修改我的延迟加载设置后,我发现在其他实体的同一实体上使用不同的fetchType会导致SHARED_CACHE模式下出现此问题。
entities
默认情况下@OneToMany是延迟提取的,但是在同一个实体的另一个实体中提供了&#39; Groups&#39;我已将fetchType配置为EAGER。
当我将两种获取类型都发送到LAZY时,此错误停止发生。