mirromutth/r2dbc-mysql

Transaction does not work in MySQL environment

pjy1368 opened this issue · 2 comments

The configuration file was created as follows.

package com.jvmhater.moduticket.configuration

import io.r2dbc.spi.ConnectionFactories
import io.r2dbc.spi.ConnectionFactory
import io.r2dbc.spi.ConnectionFactoryOptions
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.env.Environment
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories
import org.springframework.r2dbc.connection.R2dbcTransactionManager
import org.springframework.transaction.ReactiveTransactionManager

@Configuration
@EnableR2dbcRepositories
class MySQLConfiguration(private val env: Environment) : AbstractR2dbcConfiguration() {

    @Bean
    override fun connectionFactory(): ConnectionFactory {
        return ConnectionFactories.get(
            ConnectionFactoryOptions.builder()
                // ... etc connection info
                .build()
        )
    }

    @Bean
    fun transactionManager(connectionFactory: ConnectionFactory): ReactiveTransactionManager {
        return R2dbcTransactionManager(connectionFactory)
    }
}

And @transactional was added at the service layer to implement declarative transactions.

...
@Transactional(readOnly = true)
suspend fun find(id: String): Coupon {
    return couponRepository.find(id)
}
...

However, if i actually execute the above logic, an error occurs.

Receiver class dev.miku.r2dbc.mysql.MySqlConnection does not define or inherit an implementation of the resolved method 'abstract org.reactivestreams.Publisher beginTransaction(io.r2dbc.spi.TransactionDefinition)' 

I also created the ReactiveTransactionManager Bean, but why is this error occurring?

image

When I analyzed the library, MySqlConnection did not overwrite the required method, resulting in a compilation error. What is the problem?
jchrys commented

Which version of r2dbc-spi are you using?

could you try to replace dev.miku.r2dbc-mysql with io.asyncer:r2dbc-mysql:0.9.1 and see if error is still there?