mirromutth / r2dbc-mysql

R2DBC MySQL Implementation
Apache License 2.0
656 stars 98 forks source link

Transaction does not work in MySQL environment #250

Open pjy1368 opened 1 year ago

pjy1368 commented 1 year ago

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?

pjy1368 commented 1 year ago
image

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

jchrys commented 1 year ago

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?