Bug 535174 - Exception around ElementCollections and lazy loading once an entity has CacheType=ISOLATED
Summary: Exception around ElementCollections and lazy loading once an entity has Cache...
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-28 03:03 EDT by Thomas Buckel CLA
Modified: 2022-06-09 10:05 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Buckel CLA 2018-05-28 03:03:29 EDT
Hi all,

We've started making one entity in our system not cached (@Cache(isolation = CacheIsolationType.ISOLATED)) and are seeing some weird exceptions appearing in a non reproducible way. There are no other non cacheable entities.

There's an entity Equipment with a OneToMany to EffectiveAttributeValue. EffectiveAttributeValue is not cached.

public class Equipment extends BaseEntity implements HasAttachments {
    ...
    @OneToMany(mappedBy = "equipment", fetch = FetchType.LAZY)
    private List<EffectiveAttributeValue> effectiveAttributeValues = new ArrayList<>();
    ...
    @ElementCollection(fetch = FetchType.EAGER)
    @MapKeyColumn(name="DEFECT_KEY_PREFIX")
    @Column(name="SEQUENCE_NUMBER")
    @CollectionTable(name="DEFECT_KEY_SEQUENCES", joinColumns=@JoinColumn(name="EQUIPMENT_ID"))
    private Map<String, Integer> defectKeySequences = new HashMap<String, Integer>();

}

@Entity
@Cache(isolation = CacheIsolationType.ISOLATED)
@Table(name = "EFFECTIVE_ATTRIBUTE_VALUE")
@Access(AccessType.FIELD)
public class EffectiveAttributeValue {

    @EmbeddedId
    private EffectiveAttributeValueId effectiveAttributeValueId;
    ...
}

Generally it all works, but in certain instances Eclipselink fails with odd exceptions - it works as soon as the entity is cacheable. Generally it seems to be related to the cloning of objects within Eclipselink. I tracked it done to different behaviour based on the Session being a UnitOfWork or not as it seems to create an IsolatedClientSession as soon as a non cacheable entity was found.

Exception 1:
org.eclipse.persistence.exceptions.QueryException: 
Exception Description: Cannot add the object [2], of class [class java.lang.Integer], to container class [class java.util.Hashtable] using policy [MappedKeyMapContainerPolicy(class java.util.Hashtable)].
Query: ReadObjectQuery(referenceClass=Equipment )
        at org.eclipse.persistence.exceptions.QueryException.cannotAddToContainer(QueryException.java:364)
        at org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy.addInto(MappedKeyMapContainerPolicy.java:182)
        at org.eclipse.persistence.mappings.CollectionMapping.buildContainerClone(CollectionMapping.java:244)
        at org.eclipse.persistence.internal.indirection.NoIndirectionPolicy.cloneAttribute(NoIndirectionPolicy.java:76)
        at org.eclipse.persistence.mappings.ForeignReferenceMapping.readFromRowIntoObject(ForeignReferenceMapping.java:1512)
        at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildAttributesIntoObject(ObjectBuilder.java:462)
        at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildProtectedObject(ObjectBuilder.java:1160)
        at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:945)
        at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:737)
        at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:689)
        at org.eclipse.persistence.queries.ObjectLevelReadQuery.buildObject(ObjectLevelReadQuery.java:805)
        at org.eclipse.persistence.queries.ReadObjectQuery.executeObjectLevelReadQuery(ReadObjectQuery.java:564)
        at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1175)
        at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:904)
        at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1134)
        at org.eclipse.persistence.queries.ReadObjectQuery.execute(ReadObjectQuery.java:441)
        at org.eclipse.persistence.internal.sessions.AbstractSession.internalExecuteQuery(AbstractSession.java:3271)

The exception happens when an eagerly loaded Map on Equipment is loaded when Eclipselink resolves as lazily loaded reference. The eagerly loaded map is "defectKeySequences".
The used mapping classes seem correct, but in CollectionMapping.buildContainerClone() the containerPolicy's next() returns the Map.Entry's value and not the Map.Entry itself.

Exception 2:
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.size(IndirectList.java:829)
at com.inspectivity.server.domain.question.Question.getActiveObservations(Question.java:675)

Any help appreciated but it seems to me that as soon as there's a non cacheable entity things go wrong.

Unfortunately I can't really provide an isolated test case.

Cheers,
Thomas
Comment 1 Eclipse Webmaster CLA 2022-06-09 10:05:15 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink