Bug 493291 - IllegalStateException while copying cyclic object graphs
Summary: IllegalStateException while copying cyclic object graphs
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 8
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-10 04:19 EDT by ben CLA
Modified: 2022-06-09 10:04 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ben CLA 2016-05-10 04:19:08 EDT
Under certain circumstances eclipselink throws an IllegalStateException while copying an object graph with cyclic dependencies. In the folowing example A, B and C are some entity classes. A has a reference to a collection of entites of type B (B_1), B has a reference to an entity of type C and C has references to a collection of entites of type B (B_2). So if an entity of type B is part B_1 it is also part of B_2:

A -> B_1 -> C -> B_2

The exception occurrs, if the entites from B_2 are copied with a reduced AttributeGroup and the entities from B_1 are copied with a full AttributeGroup. In that case the different AttributeGroups are not merge in ObjectBuilder.copyObject (ObjectBuilder line 2700-2711).

Internal Exception: java.lang.reflect.InvocationTargetException
Target Invocation Exception: java.lang.IllegalStateException: Cannot get unfetched attribute [a] from detached object B.
Mapping: org.eclipse.persistence.mappings.ManyToOneMapping
Descriptor: RelationalDescriptor(B --> [DatabaseTable(B)])
	at org.eclipse.persistence.exceptions.DescriptorException.targetInvocationWhileSettingValueThruMethodAccessor(DescriptorException.java:1768)
	at org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor.setAttributeValueInObject(MethodAttributeAccessor.java:275)
	at org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor.setAttributeValueInObject(MethodAttributeAccessor.java:226)
	at org.eclipse.persistence.mappings.DatabaseMapping.setAttributeValueInObject(DatabaseMapping.java:1652)
	at org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy.reset(BasicIndirectionPolicy.java:273)
	at org.eclipse.persistence.mappings.ObjectReferenceMapping.buildCopy(ObjectReferenceMapping.java:142)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder.copyObject(ObjectBuilder.java:2771)
	at org.eclipse.persistence.internal.sessions.AbstractSession.copyInternal(AbstractSession.java:1141)
	at org.eclipse.persistence.mappings.CollectionMapping.copyElement(CollectionMapping.java:286)
	at org.eclipse.persistence.mappings.CollectionMapping.buildCopy(CollectionMapping.java:265)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder.copyObject(ObjectBuilder.java:2771)
	at org.eclipse.persistence.internal.sessions.AbstractSession.copyInternal(AbstractSession.java:1141)
	at org.eclipse.persistence.mappings.CollectionMapping.copyElement(CollectionMapping.java:286)
	at org.eclipse.persistence.mappings.CollectionMapping.buildCopy(CollectionMapping.java:265)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder.copyObject(ObjectBuilder.java:2771)
	at org.eclipse.persistence.internal.sessions.AbstractSession.copyInternal(AbstractSession.java:1141)
	at org.eclipse.persistence.internal.sessions.AbstractSession.copy(AbstractSession.java:1119)
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.copy(EntityManagerImpl.java:2834)
Comment 1 Eclipse Webmaster CLA 2022-06-09 10:04:45 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink