problem when primary key value is zero

#1

I am copying data from a postgres database to objectDB.

Some of the rows in the postgres table were created by postgres DDL / SQL insert statements and so do not abide by all JPA rules and recommendations, in particular there are some primary keys with value == 0. These cause problems for objectDB, typically "JPA Unexpected argument as primary key".

When using eclipselink, there is a workaround that can be added to persistence.xml like this:

<!-- next line is needed because some tables have a zero value in primary key column -->
            <property name="eclipselink.id-validation" value="NULL"/>

 

Is there a similar workaround for objectDB ?

 

#2

There is nothing wrong with 0 as a primary key value.

For example the following code doesn't throw any exception:

import javax.persistence.*;

public class T481 {
   
    public static void main(String[] args) {
        EntityManagerFactory emf =
            Persistence.createEntityManagerFactory(
                "objectdb:$objectdb/db/test.tmp;drop");
        EntityManager em = emf.createEntityManager();
       
        em.getTransaction().begin();
        em.persist(new MyEntity());
        em.getTransaction().commit();

        em.close();
        emf.close();
    }
   
    @Entity
    static class MyEntity {
        @Id long id;
    }
}

There is a problem with using the same primary key value for different entity objects, but then the error message is different ("Attempt to reuse an existing primary key value").

Please provide a full stack trace and more information about your entity class and the problem.

ObjectDB Support

Reply