Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"No transaction in context" after context refresh with spring-boot-devtools #365

Closed
alexbezhan opened this issue Aug 7, 2018 · 4 comments
Labels
bug waiting for reply Additional information required

Comments

@alexbezhan
Copy link

alexbezhan commented Aug 7, 2018

I'm getting the following error when spring context is refreshed with spring-boot-devtools:

java.lang.IllegalStateException: No transaction in context.
	at org.jetbrains.exposed.sql.transactions.TransactionManager$Companion.current(TransactionApi.kt:70) ~[exposed-0.10.4.jar:na]
	at org.jetbrains.exposed.sql.vendors.DefaultKt.getCurrentDialect(Default.kt:339) ~[exposed-0.10.4.jar:na]
	at org.jetbrains.exposed.sql.SchemaUtils.drop(SchemaUtils.kt:189) ~[exposed-0.10.4.jar:na]
	at com.alexbezhan.exposeddemo.Init.init(ExposedDemoApplication.kt:43) ~[classes/:na]

The issue occurs when I provide Exposed Table as a Spring Bean like this:

interface Repository
object Table : IntIdTable(), Repository

// and then in configuration:
@Bean
fun repo(): Repository = Table

And then I drop the table with SchemaUtils on ContextRefreshedEvent:

SchemaUtils.drop(Table)

Here is the minimal code to reproduce:

@EnableTransactionManagement
@SpringBootApplication
class ExposedDemoApplication {
    // this causes error after context refresh with spring devtools
    @Bean
    fun repo(): Repository = Table

    @Bean
    fun springTransactionManager(dataSource: DataSource): SpringTransactionManager =
            SpringTransactionManager(dataSource)
}

interface Repository

object Table : IntIdTable(), Repository

@Transactional
@Component
class Init {
    @EventListener
    fun init(event: ContextRefreshedEvent) {
        println("Init()")
        SchemaUtils.drop(Table)
        SchemaUtils.create(Table)
    }

}

fun main(args: Array<String>) {
    runApplication<ExposedDemoApplication>(*args)
}

If I don't provide Table as a Bean, then no exception is thrown.

I also created demo project that reproduces the issue.

@Tapac Tapac added the bug label Aug 26, 2018
@Tapac
Copy link
Contributor

Tapac commented Oct 19, 2018

@alexbezhan, Look similar to #407, but I can't reproduce that exception even with your demo project.
Could you please check if the workaround from this comment and the next one will help?

Tapac added a commit that referenced this issue Oct 23, 2018
…ot-devtools

#407 "No transaction in context" with multiple Spring contexts in one JVM
@alexbezhan
Copy link
Author

@Tapac Yes, that fix works. 👍

@alexbezhan
Copy link
Author

@Tapac Did you try to rebuild the demo project with devtools while running it ? It should be reproducible. I just cloned it and it still reproduces.

@Tapac
Copy link
Contributor

Tapac commented Nov 28, 2018

@alexbezhan , is this issue still reproducible on the latest Exposed (0.11.2)?

@Tapac Tapac added the waiting for reply Additional information required label Nov 28, 2018
@Tapac Tapac closed this as completed Dec 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug waiting for reply Additional information required
Projects
None yet
Development

No branches or pull requests

2 participants