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
Outer Transaction will create entities from failed inner transaction #1637
Comments
Thank you for providing the details to reproduce that. Will take a look. |
I didn't manage to reproduce this behaviour, but maybe that's because I'm running my tests on H2 database. |
I was using H2, too. I'll create a sample project and upload that later today. |
Sorry @AlexeySoshin , there were a few errors in the example from above (missing StdOutLogger, director column, ...). I've fixed the example code above. Here is the project file using Spring Boot 2.7.5 and Exposed 0.41.1 Just execute
Inside the archive you'll find the h2 db file from a single run including the db state after executing the application. This contains "Film 2" as mentioned from the logs (which is not correct behavior). Expected behavior An outer transaction should never create entities from an inner transaction, when that inner transaction didn't return without an exception. |
Problem
When an inner (as in nested) transaction will throw an exception and the outer transaction code will catch this exception, all entities from the inner transaction will be created.
This is especially problematic in tests where the test method will open a transaction (by default via Interceptor) and then call a Service which internally creates a transaction, too.
Context
Spring Boot (2.7.5) application with Exposed Starter (0.41.1).
Example
The result of the execution is
The
SQL: INSERT INTO STARWARSFILMS ("NAME", SEQUEL_ID) VALUES ('Film 2', 2)
shouldn't be there as you can clearly see that theTest case 2 inner transaction
has been terminated with anIllegalStateException
When looking into the database (H2 in my case) you can see that
Film 2
was created:Expected behavior
The outer transaction of
Test case 2
should not create the entityFilm 2
as the inner transaction (where the entity was created) encountered an exception. In general: An outer transaction should never create entities from an inner transaction if this transaction exited with an exception.useNestedTransactions = true
didn't help, either.The text was updated successfully, but these errors were encountered: