Tagged: transaction

A lesson of @Transactional

Recently, I needed to work with a Cursor for statistics.

<mapper ...>
  <select id="selectCorsor" resultOrdered="true">

It didn’t make any difference.

public interface SomeMapper {
    Cursor<Some> selectCursor(...);

We need the @Transactional annotation for working with Cursor.

public class SomeService {

    public <R> R applyCursor(
            final Function<Cursor<Some>, R> function) {
         return function.apply(someMapper.selectCursor(..));

    private SomeMapper someMapper;

Well the method worked as expected.

The problem arose when I added a method using the origin method.

    public void acceptEach(
            final Consumer<Some> consumer) {
            cursor -> {
                return null;

This auxiliary method was not annotated with @Transactional and it didn’t work.

And I found @Transactional method calling another method without @Transactional anotation?.

The acceptEach method was also required to be annotated with @Transactional​.