Merge throw exception "Attempt to reuse an existing primary key value"

Type: BugVersion: 2.6.2Priority: CriticalStatus: FixedReplies: 2
#1

Hi,

if Id = 0 I got

javax.persistence.EntityExistsException: com.objectdb.o.UserException: Attempt to reuse an existing primary key value (ru.dz.train.test.ZeroIdTest$MyEntity:0)

 

if Id=1 no exception

code :

import javax.persistence.*;

public class ZeroIdTest {
    public static void main(String[] args) {
        EntityManagerFactory emf = Persistence
                .createEntityManagerFactory("objectdb:$objectdb/db/test.tmp;drop");

        EntityManager em = emf.createEntityManager();
        final int Id = 0;
        em.getTransaction().begin();
        em.persist(new MyEntity(Id));
        em.getTransaction().commit();
        em.getTransaction().begin();
        em.merge(new MyEntity(Id));
        em.getTransaction().commit();
        em.close();
        emf.close();
    }

    @Entity
    public static class MyEntity {
        @Id
        private int Id;

        public MyEntity(int id) {
            Id = id;
        }

        public MyEntity() {
        }
    }
#2

Build 2.6.2_01 includes a fix. Thank you for this report.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#3

Thank You.

2.6.2_01 fix our problem.


Post Reply

To post a reply and/or subscribe to update notifications - please login