Details
Description
1. Create an entity which has a one-to-many relationship with other entity (MyEntity ---> MyOtherEntity)
2. Persist the entity.
3. Query the earlier created entity using JPQL.
4. Detach the entyty using OpenJPAEntityManager.detach() method.
5. Query for some entities which the created entity has a one-to-many relashionship (MyOtherEntity) and update the entity with the result of the query, i.e. myEntity.setMyOtherEntities(query.getResultList());
6. Try to attach the entity back to the persistence context using EntityManager.merge() method.
ACT: You will end up with the PersistenceException:
<openjpa-1.2.1-r752877:753278 fatal general error> org.apache.openjpa.persistence.PersistenceException: Unable to instantiate proxy for type "org.apache.openjpa.kernel.DelegatingResultList". Make sure the class has a default constructor.
at org.apache.openjpa.util.ProxyManagerImpl.instantiateProxy(ProxyManagerImpl.java:500)
at org.apache.openjpa.util.ProxyManagerImpl.getFactoryProxyCollection(ProxyManagerImpl.java:365)
at org.apache.openjpa.util.ProxyManagerImpl.copyCollection(ProxyManagerImpl.java:182)
at org.apache.openjpa.kernel.AttachStrategy.copyCollection(AttachStrategy.java:344)
at org.apache.openjpa.kernel.AttachStrategy.attachCollection(AttachStrategy.java:321)
at org.apache.openjpa.kernel.AttachStrategy.replaceList(AttachStrategy.java:359)
at org.apache.openjpa.kernel.AttachStrategy.attachField(AttachStrategy.java:223)
at org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:161)
at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:241)
at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:101)
at org.apache.openjpa.kernel.BrokerImpl.attach(BrokerImpl.java:3212)
at org.apache.openjpa.kernel.DelegatingBroker.attach(DelegatingBroker.java:1158)
at org.apache.openjpa.persistence.EntityManagerImpl.merge(EntityManagerImpl.java:769)
at test.MyEntityPersitenceTest.testAttach(MyEntityPersitenceTest.java:114)
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:73)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
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.ParentRunner.run(ParentRunner.java:220)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
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.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)