ObjectDB ObjectDB

Issue #2293: Sometimes cascade persist does not work during commit

Type: Bug ReoprtVersion: 2.7.3Priority: HighStatus: ActiveReplies: 3
#1

Hello,

sometimes our test suite runs into an unexpected behavior.

The test suite persists an entity A, afterwards not persisted entities B are added to entity A.

At the end a commit is executed and the commit persists the entities B automatically by cascading. But sometimes the cascading doesn't work correctly, so that entities B are not persisted.

Unfortunately we cannot reproduce this bug in the small example. The bug occurs only in a big context.

Do you know something about this bug?

 

// persist configuration: <cascade-persist always="auto" on-persist="true" on-commit="true" />

public class CascadePersistDoesNotWork {

    static int idCounter = 1;

    public static void main(String[] args) {

        EntityManagerFactory emf;

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

        EntityManager em = emf.createEntityManager();
        em.setFlushMode(FlushModeType.AUTO);
        em.getTransaction().begin();

        em.createQuery("DELETE from Object").executeUpdate();

        A a = new A();
        a.strValue = "A";
        a.blist = new HashSet<>();
        em.persist(a);

        for (int i = 0; i < 1; i++) {
            B b = new B();
            b.strValue = "B";
            a.blist.add(b);
        }

        em.getTransaction().commit();
        em.close();

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

        em = emf.createEntityManager();
        em.setFlushMode(FlushModeType.AUTO);
        em.getTransaction().begin();

        Query query = em.createQuery("select b from B b");
        assertEquals(1, query.getResultList().size());

        em.getTransaction().commit();
        em.close();
        emf.close();

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

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

        @Id
        int id;

        @Basic
        String strValue;

        @OneToMany (cascade = {CascadeType.ALL }, orphanRemoval = true)
        Set<B> blist;

        public A() {
            id = idCounter++;
        }
    }

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

        @Id
        int id;

        @Basic
        String strValue;

        public B() {
            id = idCounter++;
        }
    }
}

 

edit
delete
#2

Unfortunately we currently do not have any information about such issue.

ObjectDB Support
edit
delete
#3

Hello,

for this bug entry we have a workaround.

We just persist the entity tree hierarchy, if the tree hierarchy is completed.

edit
delete
#4

If the workaround is to replace intermediate flush operations with complete begin-commit transactions, then this indeed should work.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.