miran miran - 1 month ago 12x
Java Question

Using REQUIRES_NEW JTA transaction type in MyBatis on Wildfly

I am trying to use mybatis-cdi within Wildfly and I need to run part of method in separate transaction - see following snippet:

public class ItemService {

ItemMapper mapper;

public void doSomething() {
List<Item> items = mapper.findByTime(new Date());
for(Item i : items) {

public void update(Item item) {

Is this correct way how to do it? Is this supported with mybatis-cdi, or should it be done some different way?


You're not getting your expected behavior as interceptors are not applied when using a self reference in a method, for example how doSomething() calls update() directly. You would need that to occur in a separate bean to allow a separate transaction interaction.