Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 355721

Summary: ClassCastException after Commit for lazy indirection policy with QueryBasedValueHolder
Product: z_Archived Reporter: Missing name <frank_wuerffel>
Component: EclipselinkAssignee: David Minsky <david.minsky>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: david.minsky, lukas.jungmann, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed fix & test lukas.jungmann: review+

Description Missing name CLA 2011-08-24 11:32:55 EDT
Build Identifier: 2.3.0.v20110604-r9504

When I update an entity which contains a one to many relation with indirection policy lazy and a QueryBasedValueHolder then a ClassCastException is thrown after the commit.
This is reproducible and a stack trace is attached.

Reproducible: Always

Steps to Reproduce:
1. Set up an entity with a 1:n relation
2. Create a Customization Query for the 1:n relation
3. Create an entity with children
4. update the entity
Comment 1 Missing name CLA 2011-08-24 11:33:52 EDT
EL Finer]: 2011-08-24 17:24:15.786--UnitOfWork(2633275)--Thread(Thread[main,5,main])--TX afterCompletion callback, status=COMMITTED
[EL Finer]: 2011-08-24 17:24:15.786--UnitOfWork(2633275)--Thread(Thread[main,5,main])--end unit of work commit
8922 [main] WARN atomikos - Error during afterCompletion
java.lang.ClassCastException: org.eclipse.persistence.internal.indirection.QueryBasedValueHolder cannot be cast to org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder
	at org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy.buildBackupClone(TransparentIndirectionPolicy.java:82)
	at org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy.backupCloneAttribute(TransparentIndirectionPolicy.java:68)
	at org.eclipse.persistence.mappings.ForeignReferenceMapping.buildBackupClone(ForeignReferenceMapping.java:224)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildBackupClone(ObjectBuilder.java:503)
	at org.eclipse.persistence.descriptors.changetracking.DeferredChangeDetectionPolicy.buildBackupClone(DeferredChangeDetectionPolicy.java:206)
	at org.eclipse.persistence.descriptors.changetracking.DeferredChangeDetectionPolicy.revertChanges(DeferredChangeDetectionPolicy.java:270)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.resumeUnitOfWork(UnitOfWorkImpl.java:5205)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.synchronizeAndResume(UnitOfWorkImpl.java:5154)
	at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.synchronizeAndResume(RepeatableWriteUnitOfWork.java:548)
	at org.eclipse.persistence.transaction.AbstractSynchronizationListener.afterCompletion(AbstractSynchronizationListener.java:232)
	at org.eclipse.persistence.transaction.JTASynchronizationListener.afterCompletion(JTASynchronizationListener.java:79)
	at com.atomikos.icatch.jta.Sync2Sync.afterCompletion(Sync2Sync.java:73)
	at com.atomikos.icatch.imp.SynchToFSM.doAfterCompletion(SynchToFSM.java:63)
	at com.atomikos.icatch.imp.SynchToFSM.entered(SynchToFSM.java:84)
	at com.atomikos.finitestates.FSMImp.notifyListeners(FSMImp.java:185)
	at com.atomikos.finitestates.FSMImp.setState(FSMImp.java:276)
	at com.atomikos.icatch.imp.CoordinatorImp.setState(CoordinatorImp.java:521)
	at com.atomikos.icatch.imp.CoordinatorImp.setStateHandler(CoordinatorImp.java:351)
	at com.atomikos.icatch.imp.CoordinatorStateHandler.commit(CoordinatorStateHandler.java:687)
	at com.atomikos.icatch.imp.ActiveStateHandler.commit(ActiveStateHandler.java:289)
	at com.atomikos.icatch.imp.CoordinatorImp.commit(CoordinatorImp.java:863)
	at com.atomikos.icatch.imp.CoordinatorImp.terminate(CoordinatorImp.java:1157)
	at com.atomikos.icatch.imp.CompositeTerminatorImp.commit(CompositeTerminatorImp.java:92)
	at com.atomikos.icatch.jta.TransactionImp.commit(TransactionImp.java:236)
	at com.atomikos.icatch.jta.TransactionManagerImp.commit(TransactionManagerImp.java:498)
	at com.atomikos.icatch.jta.UserTransactionImp.commit(UserTransactionImp.java:129)
	at com.siemens.energy.td.org.server.persistence.jpa.OrgPersistenceAccessTestBase$9.commit(OrgPersistenceAccessTestBase.java:198)
	at com.siemens.energy.td.org.server.business.SocOrgManager.synchronizeSocOrgsRecursive(SocOrgManager.java:127)
	at com.siemens.energy.td.org.server.business.SocOrgManager.synchronizeOrgTreeWithSocOrgTree(SocOrgManager.java:111)
	at com.siemens.energy.td.org.server.business.SocOrgManager.synchronizeOrgTreeWithSocOrgTree(SocOrgManager.java:106)
	at com.siemens.energy.td.org.server.business.SocOrgManagerTest.testCreateNewSocOrg(SocOrgManagerTest.java:188)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Comment 2 Missing name CLA 2011-08-25 04:12:41 EDT
Common superclass would be DatabaseValueHolder but DatabaseValueHolders doesn't have the setBackupValueHolder method.
Comment 3 Tom Ware CLA 2011-09-22 11:34:41 EDT
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 4 David Minsky CLA 2015-01-28 17:23:28 EST
Created attachment 250326 [details]
Proposed fix & test

Proposed fix and test.

Resolves issue in TransparentIndirectionPolicy buildBackupClone() by not assuming that the pased IndirectContainer is a UnitOfWorkValueHolder. The existing behavior is otherwise maintained.
Comment 5 Lukas Jungmann CLA 2015-01-28 17:47:44 EST
Comment on attachment 250326 [details]
Proposed fix & test

new files (PetStore) should have just current year in the cp header, other than that the fix looks good
Comment 6 David Minsky CLA 2015-01-29 15:18:14 EST
Checked into master (2.6.0) at: 7035ac2c0aad06ae858a8a449bb750d71cde8fde

- Fix to TransparentIndirectionPolicy buildBackupClone to prevent a ClassCastException when the passed ValueHolder is not a UnitOfWorkValueHolder
- Testing: added EntityManagerJUnitTestCase testJoinedInheritancePersistWithReadOnlyEntity
Comment 7 Eclipse Webmaster CLA 2022-06-09 10:08:18 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink