The following error is reported for objectdb-2.6.9.jar:
Failed to commit transaction: Failed to set numeric value of field property com.greensoft.objectdb.test.entity.Element.id using reflection (error 613)
Did not happen with objectdb-2.6.3_04 (which one can easily test and compare in the test console app for NetBeans8.1 provided, as explained below).
To reproduce download the app and unpack, open in NetBeans8.1, perform Clean and Build, and Run:
https://www.webel.com.au/downloads/objectdb/GreensoftObjectdbTestNoweb.2016-08-15.GS4230.tgz
com.greensoft.objectdb.test.console.Main.
There is an Ant script with post-compile enhancement of all entity classes. When you clean and build it will report:
Java/JVM version: 1.8 Java/JVM detail version: 1.8.0_74 ObjectDB enhancer: begin: (all classes within entity packages): javac.classpath:lib/objectdb-2.6.9.jar [ObjectDB 2.6.9 Enhancer] 8 persistable types have been enhanced: com.greensoft.objectdb.test.entity.Constraint com.greensoft.objectdb.test.entity.Element com.greensoft.objectdb.test.entity.Link com.greensoft.objectdb.test.entity.Permissions com.greensoft.objectdb.test.entity.Project com.greensoft.objectdb.test.entity.Source com.greensoft.objectdb.test.entity.Tag com.greensoft.objectdb.test.entity.TagSet 1 NON persistable type has been enhanced: com.greensoft.objectdb.test.entity.Role ObjectDB enhancer: end: (all classes within entity packages):
The entity model is built and persisted in Main in protected void createProject(EntityManagerFactory emf):
protected void createProject(EntityManagerFactory emf) { format().outHeader2("Create Project and Element model ..."); Project project = new Project(null, "project"); //NB: Project has no project and no owner Element model = new Element(project, project, "model");//NB: model has Project as owner project.addOwnedElement(model); Element example = new Element(model, project, "example element"); example.setHelp("Note owner of this is a model Element"); model.addOwnedElement(example); ...
EntityManager em = emf.createEntityManager(); format().out("Persist project.."); em.getTransaction().begin(); em.persist(project); //rely on Cascade all on ownedElements. em.getTransaction().commit(); ...
On attempting to persist it get error:
Create EntityManagerFactory .. ****** Create Project and Element model ... ****** Persist project.. Exception in thread "main" [ObjectDB 2.6.9] javax.persistence.RollbackException Failed to commit transaction: Failed to set numeric value of field property com.greensoft.objectdb.test.entity.Element.id using reflection (error 613) at com.objectdb.jpa.EMImpl.commit(EMImpl.java:290) at com.greensoft.objectdb.test.console.Main.createProject(Main.java:86) at com.greensoft.objectdb.test.console.Main.run(Main.java:198) at com.greensoft.objectdb.test.console.Main.main(Main.java:223) Caused by: javax.persistence.PersistenceException: com.objectdb.o.UserException: Failed to set numeric value of field property com.greensoft.objectdb.test.entity.Element.id using reflection at com.objectdb.o._PersistenceException.b(_PersistenceException.java:47) at com.objectdb.o.JPE.g(JPE.java:145) at com.objectdb.o.JPE.g(JPE.java:78) ... 6 more Caused by: com.objectdb.o.UserException: Failed to set numeric value of field property com.greensoft.objectdb.test.entity.Element.id using reflection at com.objectdb.o.MSG.d(MSG.java:75) at com.objectdb.o.UMR.P(UMR.java:936) at com.objectdb.o.UMR.I(UMR.java:766) at com.objectdb.o.VGN.e(VGN.java:76) at com.objectdb.o.MMM.Q(MMM.java:710) at com.objectdb.o.MMM.P(MMM.java:697) at com.objectdb.o.ENH.f(ENH.java:361) at com.objectdb.o.ENH.f(ENH.java:337) at com.objectdb.o.STM.E(STM.java:422) at com.objectdb.o.OBM.bP(OBM.java:931) at com.objectdb.jdo.PMImpl.bP(PMImpl.java:2279) at com.objectdb.o.OBM.bO(OBM.java:842) at com.objectdb.o.OBM.bM(OBM.java:751) at com.objectdb.jpa.EMImpl.commit(EMImpl.java:287) ... 3 more Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.objectdb.o.UMR$ac.E(UMR.java:1402) at com.objectdb.o.UMR$S.J(UMR.java:1025) at com.objectdb.o.UMR.I(UMR.java:763) ... 14 more Caused by: com.objectdb.o._IllegalArgumentException: Attempt to modify a primary key of a managed object: com.greensoft.objectdb.test.entity.Project#null at com.objectdb.o._IllegalArgumentException.b(_IllegalArgumentException.java:43) at com.objectdb.o.JPE.g(JPE.java:107) at com.objectdb.o.ERR.f(ERR.java:56) at com.objectdb.o.OBC.onObjectDBError(OBC.java:1556) at com.objectdb.o.ENT.al(ENT.java:1676) at com.objectdb.o.ENT.beforeModifyMember(ENT.java:1179) at com.greensoft.objectdb.test.entity.Element.setId(Element.java:1) ... 21 more
To compare with objectdb-2.6.3_04.jar
Under /lib there are 2 versions:
lib/objectdb-2.6.3_04.jar* lib/objectdb-2.6.9.jar
In top-level build.xml change this property to use that version during enhancement (use File view mode not Project view mode in NetBeans to find and edit it):
<property name="objectdbjar" value="./lib/objectdb-2.6.3_04.jar"/>
Then under the project libraries with NetBeans delete the lib/objectdb-2.6.9.jar and add the lib/objectdb-2.6.3_04.jar.
Clean and Build, and it enhances fine, then Run without error.
---
This is high priority for me; the same error (and another one to be reported following) also happens in a number of work projects and only with newer versions higher than objectdb-2.6.3_04.jar (although I have not done thorough bracketing of this one yet to find out which version introduced it.
If it is an error in my own entity model coding, then it is one that has only expressed itself in recent ObjectDB versions.
It prevents any attempt on my part to upgrade ObjectDB to avoid other errors (and to benefit from other fixes you have performed).