The way to do this is by creating a new context. Within this context you can call startTransaction and endTransaction() to control your transaction. Do not end the transaction started in your regular context, this could lead to weird behavior.
So in pseudo code (typing this by head) :
IContext newContext = currentContext.getSession().getContext();
newContext.startTransaction();
//do stuff with your new context
newContext.endTransaction();
Super valuable info. Was banging my head against this problem for over a day, wondering why records weren't getting written to the database.
Mendix will start a database transaction for each invocation from a user (or external system) containing an action which involves database interaction. The transaction will be started at the first database action.
transactions typically end when the commit or rollback operation is executed. In the context of Mendix, a transaction refers to a unit of work that is performed against a database.
In Mendix, transactions typically end with the completion of the logic execution, not necessarily with the last database interaction.