Using datamanager results in loosing relation to another entity

Hi,

can you help me somehow resolve this?

I have entity A which is related (many_to_one) to entity B.
in bean i have function which loads entity A via

EntityManager.createNativeQuery

then in another function i want to edit som data in entity A. using

A.setSomeColumn(some_value);
datamanager.comit(A);

which results in edited entity A but lost relation to entity B.

How shoul i approach this?

Figured out using:

public void saveEntity(Some entity) {
        try (Transaction tx = persistence.createTransaction()) {
            EntityManager em = persistence.getEntityManager();
            em.merge(entity);
            tx.commitRetaining();
        }
    }
1 Like