I get the following error when I try to access Lazy loaded @oneToMany relationship attribute in a method present in Entity.
Error:
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:
@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..
}
}
}
I've looked upon in eclipselink forum but they don't address this issue explicitly and some links say it's related to weaving.But in my application I haven't enabled weaving at all and I also don't intend to do.
This code works fine on Eclipselink 2.3.2 without JPA. Now I'm using Eclipselink 2.6.3 with JPA 2.0 and IBM Websphere 8.5.5.8.
Note: This issue occurs randomly not every time and also when ever a new object is created is what I have observed.
After many hit and trails and correcting my lazy loading settings, I've found out that using different fetchType on same entity in other entities can cause this issue in SHARED_CACHE mode.
@OneToMany(cascade=CascadeType.ALL, mappedBy="groupBase", targetEntity=Groups.class)
@PrivateOwned
private List groups = new ArrayList<>();
By default @OneToMany is lazily fetched but in another entity for the same entity 'Groups' I had configured fetchType as EAGER.
When I made both fetch types to LAZY this error stopped occurring.