How to handler transaction?


I have a question regarding the database transaction.

Understand that the screen have DataContext to track the object and commit to database after completion.

As per my situation, i want to create different entity object when the screen being saved.

My question is, i try to use DataManager to save the new entity, but screen entity will not be inside the DataContext transaction.

Is that JMIX recommend that all the new entity need to merge to DataContext and let DataContext to handler the new entity and also the transaction?

And how if i want to use SaveContext and pass to DataManager to persist the screen entity and the all the new entity objects? Or is not recommended?

1 Like

Hi @lleeding

You can easily add arbitrary entities to SaveContext using the DataContext.PreCommitEvent handler, for example:

@Subscribe(target = Target.DATA_CONTEXT)
public void onPreCommit(DataContext.PreCommitEvent event) {

So your entity will be saved in the same transaction as the rest of modified data.

1 Like

Hi @krivopustov ,

Thank you so much.
Understand on the solution.