1

Assume I have 3 different classes, A, B & C. C is designed to have a list of As and Bs.

If load a list of As and Bs and keep them attached, how can I set them as lists in a transient C object and persisting the transient object ?

The problem is that each of As and Bs lists are managed by different PersistenceManagers. So if I try to persist a transient C object with a list of As (attached, managed by a PersistenceManager) and a list of Bs (attached, managed by a second PersistenceManager), I'll get an exception saying that the As and Bs are being managed by a different PersistenceManager.

Is there an efficient way to resolve this instead of having to reload all the lists again by the one PersistenceManager responsible for persisting the C object ?

Muhammad Gelbana
  • 3,890
  • 3
  • 43
  • 81
  • errm, you attach them in the same persistence context as you want to use them in. no idea why you'd be playing around with multiple persistence contexts – Neil Stockton Aug 17 '14 at 11:07
  • I have a service specialized in representing `A` objects to the user (HTML select element) and automatically decodes the submitted value (ie. ID) to a Java object which is still attached so the editing process is managed easily. If JDO doesn't support this then I'll just have to implement another service that returns detached objects instead. But I think this is a lot of work done only to link an object to another. They both must be attached and loaded with the same PM. Is that the only way to do this ? – Muhammad Gelbana Aug 17 '14 at 12:49
  • If two objects are related and need attaching then clearly they must be attached using the same PM. Or you attach one without the relation, then when attaching the other you relate it to the already attached other object. Can't see what other requirement there is – Neil Stockton Aug 18 '14 at 06:42

0 Answers0