I am trying to use Exposed with SpringBoot and MySQL.
When I use two transaction s, First transaction is executed.
But second transaction is ignored without errors.
Can I use multi transactions?
This is based on a tutorial of Spting Boot.
https://spring.io/guides/tutorials/spring-boot-kotlin/
@RestController
@RequestMapping("/api/article")
class ArticleController() {
@GetMapping("/test")
fun test(): List<String> {
transaction {
User.insert {
it[login] = "no1_" + java.lang.Math.random()
it[firstname] = "one"
it[lastname] = "one"
it[description] = Date().toString()
}
}
transaction {
User.insert {
it[login] = "no2_" + java.lang.Math.random()
it[firstname] = "two"
it[lastname] = "two"
it[description] = Date().toString()
}
}
return listOf<String>("test")
}
mysql> select * from User;
+----+------------------------+-----------+----------+------------------------------+
| id | login | firstname | lastname | description |
+----+------------------------+-----------+----------+------------------------------+
| 17 | no1_0.9963653238062685 | one | one | Mon Mar 09 13:01:29 JST 2020 |
+----+------------------------+-----------+----------+------------------------------+
When I tried again, I got error java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30001ms. .
That looks waiting for transaction to be committed.
implementation("org.jetbrains.exposed:exposed-spring-boot-starter:0.21.1")
implementation("org.jetbrains.exposed:exposed-java-time:0.21.1")
implementation("mysql:mysql-connector-java:8.0.19")
Could you please add a logger to ensure that statement from the second transaction was executed and not commited.
Read on how to add a logger here
Thank you for your answer.
I added addLogger(StdOutSqlLogger) both transactions.
SQL: INSERT INTO `User` (description, firstname, lastname, login) VALUES ('Tue Mar 10 10:21:58 JST 2020', 'one', 'one', 'no1_0.0237269963158524')
SQL: INSERT INTO `User` (description, firstname, lastname, login) VALUES ('Tue Mar 10 10:21:58 JST 2020', 'two', 'two', 'no2_0.8000914424944682')
SQL: INSERT INTO `User` (description, firstname, lastname, login) VALUES ('Tue Mar 10 10:21:58 JST 2020', 'two', 'two', 'no2_0.8000914424944682')
Second transaction looks duplicated.
But they were not inserted… 😭
That was also occurred with H2 database.
Do you have any exceptions in your code inside the transaction block? Could you share a sample project to reproduce?
Thank you so much!
I got no error. I shared a sample project 👍
https://github.com/kaibadash/exposed_ignored_transaction
Thank you for a sample it was very helpful.
Now I found and fixed the issue and it will be available in the next release
Most helpful comment
Thank you for a sample it was very helpful.
Now I found and fixed the issue and it will be available in the next release