DataManager.reload after EntityManager.flush hangs the server on Cuba 6.10.9

See this test.

For the lazy:

public void doTest() {
    DataManager dm = AppBeans.get(DataManager.class);
    Metadata m = AppBeans.get(Metadata.class);
    Persistence p = AppBeans.get(Persistence.class);

    NewEntity entity;
    try (Transaction tx = p.createTransaction()) {
        EntityManager em = p.getEntityManager();
        entity = m.create(NewEntity.class);
        em.persist(entity);
        em.flush();
        //entity = em.find(NewEntity.class, entity.getId(), new View(NewEntity.class));
        dm.reload(entity, new View(NewEntity.class));
        tx.commit();
    }
}

The DataManager.reload call deadlocks but the EntityManager.find call does not (same on MSSQL and HSQLDB). I feel like flush must lock tables it writes to until the transaction ends, but, if that’s the case, I’m not sure why EntityManager.find would not deadlock when DataManager.reload does.

Any ideas?

Hi,

It’s because of nested transaction. DataManager always works in its own transaction.
In your case DataManager tries to fetch row which was just inserted by not yet committed transaction.

1 Like

By the way, do you know that DataManager.reload(e, View) does not affect passed instance and returns a new one with reloaded data?

Yes, thank you Yuriy. This was just a slapped-together proof of concept.

The main driver of using DataManager in the middleware was to make access to dynamic attributes easier. Is the only other option querying for the CategoryAttributeValue entities with EntityManager? Or is there an EntityManager equivalent of LoadContext.setLoadDynamicAttributes?

If you are using Platform 6.10 there is TransactionalDataManager bean. You could use it to load/save dynamic attributes in the same transaction.