Manually recording field audits - Help

Hello, I require assistance. I would like to manually log some audit fields with EntityLog.registerModify(), but it is not allowing me to log them. I have the entity registered for manual auditing in my configuration. Could someone please assist me?

Hi Bladimir,

The manual registration of changes by EntityLog works only for managed JPA entities changed within a transaction. For example:

@Component
public class SampleBean {

    @Autowired
    private EntityLog entityLog;

    @PersistenceContext
    private EntityManager entityManager;

    @Transactional
    public void doSomething(Department department) {
        Department foundDepartment = entityManager.find(Department.class, department.getId());
        foundDepartment.setName("New name");
        entityLog.registerModify(foundDepartment);
        // implicitly saved on transaction commit
    }
}

So it has very limited use. Please note that DataManager always returns detached entities, so this method will not register changes when you use DataManager even within a transaction.

We’ll update the docs to make these limitations clear.

Regards,
Konstantin