Problem with bidirectional link

#1

(I had raised this issue in the past and have finally had time to come back to it and strip down the classes to a minimum).

The problem seems to lie in having bidirectional links (viz, I have @OneToMany Map<String, Entry> children and @ManyToOne Entry parent in my classes. I've attached the offending classes. If I add an entry to the children I get an error. I'm wondering if it's a question of multiple references to the same instance of a class? It's hard to tell with the opaque code of ObjectDB.

Exception in thread "main" [ObjectDB 2.3.6] javax.persistence.RollbackException
Failed to commit transaction: Attempt to persist a reference to a non managed Folder instance - field Folder.children (error 613)
at com.objectdb.jpa.EMImpl.commit(EMImpl.java:279)
at F380.main(F380.java:20)
Caused by: javax.persistence.PersistenceException: com.objectdb.o.UserException: Attempt to persist a reference to a non managed Folder instance - field Folder.children
at com.objectdb.o._PersistenceException.b(_PersistenceException.java:47)
at com.objectdb.o.JPE.g(JPE.java:140)
at com.objectdb.o.JPE.g(JPE.java:78)
... 4 more
Caused by: com.objectdb.o.UserException: Attempt to persist a reference to a non managed Folder instance - field Folder.children
at com.objectdb.o.MSG.d(MSG.java:61)
at com.objectdb.o.TYW.writeElement(TYW.java:257)
at com.objectdb.o.MPT.writeStrictly(MPT.java:243)
at com.objectdb.o.TYW.ar(TYW.java:393)
at com.objectdb.o.TYW.av(TYW.java:474)
at com.objectdb.o.TYW.writeElement(TYW.java:273)
at com.objectdb.o.UMR$P.y(UMR.java:960)
at com.objectdb.o.UMR.x(UMR.java:549)
at com.objectdb.o.UML.u(UML.java:515)
at com.objectdb.o.MMM.af(MMM.java:1033)
at com.objectdb.o.UTY.aG(UTY.java:1195)
at com.objectdb.o.UTY.aF(UTY.java:1184)
at com.objectdb.o.ENH.a(ENH.java:46)
at com.objectdb.o.STA.T(STA.java:512)
at com.objectdb.o.STM.E(STM.java:425)
at com.objectdb.o.OBM.bI(OBM.java:888)
at com.objectdb.jdo.PMImpl.bI(PMImpl.java:2186)
at com.objectdb.o.OBM.bH(OBM.java:804)
at com.objectdb.o.OBM.bF(OBM.java:719)
at com.objectdb.jpa.EMImpl.commit(EMImpl.java:276)
... 1 more
#2

Many issues have been fixed since version 2.3.6.

Please try the last ObjectDB version (2.4.0_01) and if the problem still exists it will be examined.

ObjectDB Support
#3

Problem continues with 2.4.0_01 Same traceback as above, but with newer version number in the message.

#4

The cause of the problem is that all the Folder instances are persisted with the same id = 0.

You can easily solve the problem by annotating the id field with @GeneratedValue.

I will check how the error message that ObjectDB produces in this case can be improved.

ObjectDB Support

Reply