101 words

Issue #256 - Merge throw exception "Attempt to reuse an existing primary key value"

BugVersion: 2.6.2Priority: CriticalStatus: FixedReplies: 2
#1
2015-05-21 19:15

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() {
        }
    }
uncol
uncol's picture
Joined on 2013-12-29
User Post #3
#2
2015-05-22 13:22

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

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #2,210
#3
2015-05-22 17:55

Thank You.

2.6.2_01 fix our problem.

uncol
uncol's picture
Joined on 2013-12-29
User Post #4

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel