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.