ObjectDB ObjectDB

Failed to commit transaction: Attempt to reuse an existing primary key value (613)

#1

I am using ObjectDB 2.8.3 version for my University Project which currently i am trying to inplement an Integration testing to one of my DataAccess methods. But, the problem comes before i try the method i want to be proved, exactly when i try to set up the database. These one is the test method.


@Test
    public void testONA() {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
            Date oneDate=null;
            ap= new ArrayList<Pronostikoa>();
            try {
                oneDate = sdf.parse("05/10/2022");
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            bez=testBL.addBezeroa("Jon", "Smith", "Clark", "SmithClark", "ClarkSmith", "123456789", "jonsc@gmail.com",
                    new Date(2001, 8, 1));
            ev=testBL.addEventWithQuestion("event1", oneDate, "question1", 2);
            System.out.println(bez);
            q=ev.getQuestions().get(0);
            System.out.println(q.getEvent());
            pronos=testBL.addPronostikoatoQuestion(q, "pronostic1", 2);
            System.out.println(pronos);
            ap.add(pronos);
            System.out.println(pronos.getIdentifikadorea());
            bez=testBL.addApustua(ap, 4, bez);
            apu=testBL.getBezeroApustu(bez, ap);
            System.out.println(apu);
            System.out.println(apu.getPronostikoak());
            System.out.println(testBL.getBezeroApustu(bez, ap));
            bez=sut.deleteApustua(apu);
            assertTrue(bez.baduApustua(apu)==null);
        }catch(Exception e) {
            e.printStackTrace();
            fail();
        }finally {
            testBL.removeBezeroa(bez);
            testBL.removeEvent(ev);
            //testBL.removeApustua(apu);
        }
    }

The problem comes when i do the call testBL.addApustua() method, where it throws this error and with e.printStackTrace i try to figure where is the problem. 

[ObjectDB 2.8.3] javax.persistence.RollbackException
Failed to commit transaction: Attempt to reuse an existing primary key value (domain.Pronostikoa:72) (error 613)
    at com.objectdb.jpa.EMImpl.commit(EMImpl.java:289)
    at test.dataAccess.TestDataAccess.addApustua(TestDataAccess.java:264)
    at test.businessLogic.TestFacadeImplementation.addApustua(TestFacadeImplementation.java:76)
    at DeleteApustuaInt.testONA(DeleteApustuaInt.java:162)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:93)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: javax.persistence.EntityExistsException: com.objectdb.o.UserException: Attempt to reuse an existing primary key value (domain.Pronostikoa:72)
    at com.objectdb.o._EntityExistsException.a(_EntityExistsException.java:46)
    at com.objectdb.o.JPE.d(JPE.java:100)
    at com.objectdb.o.JPE.d(JPE.java:80)
    ... 33 more

 

The problem it tolds to me is that when i try to create a class (Apustua) which contains other class objects list (ArrayList<Pronostikoa>)  i don´t know why the ID used to create it is the same as it has the Pronostikoa object , which could not be the same theoricaly i think cause in both cases the @Id in the database is @GeneratedValue, and at the commit clause it throws the exception. If you could explain to me why is it happening  i would be grateful with you cause i am having this problem for 2-3 weeks and on Internet there is no information about it. 

 

I know that maybe my explanation is not the best one, in that case tell to me and i will try to explane it better.

edit
delete
#2

Assuming the error message is correct - you are trying to store more than one object in the database with the same primary key.

Unfortunately it is impossible to provide help based on this report and the fragment of code, which do not include the relevant information regarding the exception.

To explore this issue further you will have to provide a minimal runnable program in a one file format, which demonstrates the issue.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.