当我试图访问实体中存在的方法中的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论坛上看过,但是他们没有明确地解决这个问题,有些链接说它与我的应用程序中的weaving.But有关,我根本没有启用过编织,我也不打算这么做。
这段代码在没有JPA的Eclipselink 2.3.2上运行得很好。现在,我在JPA2.0和IBM 8.5.5.8中使用Eclipselink 2.6.3。
注意:我观察到,这个问题并非每次都会随机发生,而且当创建新对象时也是如此。
发布于 2017-08-16 17:22:17
经过多次点击和跟踪,并纠正了我的延迟加载设置,我发现在其他实体中对同一个实体使用不同的fetchType会在SHARED_CACHE模式下导致这个问题。
@OneToMany(cascade=CascadeType.ALL, mappedBy="groupBase", targetEntity=Groups.class)
@PrivateOwned
private List groups = new ArrayList<>();默认情况下,@OneToMany是延迟获取的,但是在另一个实体中,对于同一个实体“组”,我将fetchType配置为急切。
当我将两种提取类型都设置为惰性时,此错误将停止发生。
https://stackoverflow.com/questions/44366176
复制相似问题