spring-bootjooq

Cannot use ContextTransactionalCallable with TransactionProvider


I have an error, which I can't solve.

I am using Spring and JOOQ.

Error occurs here:

   @Transactional
    public UUID create(List<User> users) {
        UUID uuid = UUID.randomUUID();
        dslContext.transaction(() -> {
            dslContext
                    .insertInto(APPLE, APPLE.APPLE_ID, APPLE.TITLE)
                    .values(uuid, uuid.toString())
                    .execute();

            users.forEach(user -> {
                dslContext
                        .insertInto(APPLE_MEMBERS, APPLE_MEMBERS.APPLE_ID, APPLE_MEMBERS.USER_ID)
                        .values(uuid, user.getUserId())
                        .execute();
            });

        });

        return uuid;
    }

Error:

org.jooq.exception.ConfigurationException: Cannot use ContextTransactionalCallable with TransactionProvider of type class org.springframework.boot.autoconfigure.jooq.SpringTransactionProvider

Maybe someone had same error or has idea how to solve this error?


Solution

  • Using out of the box features:

    You have to pick one of the two approaches:

    1. Spring's declarative transaction management through annotations
    2. jOOQ's programmatic transaction management through its API

    Out of the box, they cannot be combined. In your particular case, I don't see why you would want to do it. The nested, programmatic transaction has the exact same scope as the outer, declarative transaction. It is redundant.

    Using custom TransactionProvider implementations

    You could write your own TransactionProvider that is able to communicate with Spring's transaction management and allows for embedding nested transactions in @Transactional annotated methods, but I generally advise against it. Pick one of the two approaches.