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

Cannot use multi transactions? #831

Closed
kaibadash opened this issue Mar 9, 2020 · 5 comments
Closed

Cannot use multi transactions? #831

kaibadash opened this issue Mar 9, 2020 · 5 comments

Comments

@kaibadash
Copy link

kaibadash commented Mar 9, 2020

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?

example

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.

environments

    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")
@Tapac
Copy link
Contributor

Tapac commented Mar 9, 2020

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

@kaibadash
Copy link
Author

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.

@Tapac
Copy link
Contributor

Tapac commented Mar 12, 2020

Do you have any exceptions in your code inside the transaction block? Could you share a sample project to reproduce?

@kaibadash
Copy link
Author

Thank you so much!
I got no error. I shared a sample project 👍
https://github.com/kaibadash/exposed_ignored_transaction

Tapac added a commit that referenced this issue Mar 14, 2020
…ansaction` block

SpringTransactionManager has connection leak when used with `transaction` instead of @transaction annotation
#831
@Tapac
Copy link
Contributor

Tapac commented Mar 14, 2020

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

@Tapac Tapac closed this as completed Mar 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants