ObjectDB ObjectDB

Update more than 10000 entities by an update query fails

#1

Hello,

following example tries to update more than 10000 entities by an update query.

But only the first 10000 elements are updated.

What's wrong?

 

public class updateMoreThan10000Elements {

    static int idCounter = 1;

    public static void main(String[] args) {

        EntityManagerFactory emf;
        emf = Persistence.createEntityManagerFactory("objectdb:./db.tmp;drop");

        EntityManager emOne = emf.createEntityManager();
        emOne.getTransaction().begin();
        emOne.setFlushMode(FlushModeType.AUTO);
        {
            create10001Elements(emOne);

        }
        emOne.getTransaction().commit();
        emOne.close();

        EntityManager emTwo = emf.createEntityManager();
        emTwo.getTransaction().begin();
        emTwo.setFlushMode(FlushModeType.AUTO);
        {
            String query = "UPDATE " + MyModelElement.class.getName() + " c " +
                "SET c.visible = true";

            Query q = emTwo.createQuery(query);

            q.executeUpdate();
        }

        emTwo.getTransaction().commit();
        emTwo.close();

        EntityManager emThree = emf.createEntityManager();
        emThree.getTransaction().begin();
        emThree.setFlushMode(FlushModeType.AUTO);
        {
            assertTrue(emThree.find(MyModelElement.class, 10000).isVisible());
            assertTrue(emThree.find(MyModelElement.class, 10001).isVisible());

        }

        emTwo.getTransaction().commit();
        emTwo.close();

        emf.close();

        System.out.println("All done.");
    }

    /**
     * Brief Function description
     *
     * @param emOne
     *
     */
    private static void create10001Elements(EntityManager emOne) {
        for (int i = 1; i < 10002; i++) {
            emOne.persist(new MyModelElement());
        }
    }

    @Access (AccessType.FIELD)
    @Entity
    public static class MyModelElement {

        @Id
        int id;

        @Version
        long version;

        @Basic
        boolean visible = false;

        /** Constructor */
        public MyModelElement() {
            id = idCounter++;
        }

        public int getId() {
            return this.id;
        }

        public boolean isVisible() {
            return this.visible;
        }

    }
}

 

edit
delete
#2

Thank you for this report. We can confirm that this is a bug. It could be related to flush changes in recent builds. We will try to fix it now.

ObjectDB Support
edit
delete
#3

Please try build 2.7.5_06 that should fix this issue.

ObjectDB Support
edit
delete
#4

Hello,

unfortunately the fix causes the issue https://www.objectdb.com/forum/2027 again.

 

public final class UT_Forum2027 {

    /**
     * Test for ObjectDB issue
     */
    @Test
    public void unexpectedExeption() {

        EntityManagerFactory emf = TestEntityManagerFactory.createEntityManagerFactory(true);
        EntityManager em = emf.createEntityManager();

        //"create and persist"
        em.getTransaction().begin();
        EntityA entity = new EntityA(1);
        em.persist(entity);
        em.getTransaction().commit();

        //"load and remove"
        em.getTransaction().begin();
        EntityA persitedEntity = em.find(EntityA.class, 1);
        em.remove(persitedEntity);

        //"create and persist AGAIN"

        // create a new entity with the same id which was already removed!
        EntityA entityNew = new EntityA(1);
        em.persist(entityNew);
        em.getTransaction().commit();

        em.close();
        emf.close();
    }

    /**
     * This EntityA
     */
    @Entity
    @Access (AccessType.FIELD)
    public static class EntityA {

        /**
         * primaryKex
         */
        @Id
        int id;

        /**
         * Constructor
         *
         * @param id primaryKex
         */
        public EntityA(int id) {
            this.id = id;
        }

    }
}
edit
delete
#5

Are you sure that this last fix in build 2.7.5_06 causes issue 2027 again?

It still happens when this fix is disabled.

Maybe the recent change for issue 2280, which also affects issue 2333 causes it?

Actually issue issue 2333 and issue 2027 seem to be related, but no test case was provided to demonstrate issue 2333. We may be able to use the test case of issue 2027 for both now.

ObjectDB Support
edit
delete
#6

After further investigation it is unclear if the regression in  issue 2027 (which is fixed again now) is related to issue 2280 and issue 2333.

However, it doesn't seem to be related to this issue, so this issue is considered as fixed.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.