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

Fix nested transaction savepoint handling in JDBC transaction manager #3047

Merged
merged 7 commits into from
Aug 5, 2024

Conversation

radovanradic
Copy link
Contributor

Added transaction tests for other dialects that were missing.

@radovanradic radovanradic added the type: bug Something isn't working label Aug 1, 2024
@@ -63,6 +63,10 @@ abstract class AbstractTransactionSpec extends Specification implements TestProp
return false
}

boolean failsInsertInReadOnlyTx() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some drivers don't fail when saving in read only transaction so needed to adjust existing read only tests

* @param transactionName The transaction name
* @return savepoint name for given transaction name
*/
private static String getSavepointName(String transactionName) {
Copy link
Contributor Author

@radovanradic radovanradic Aug 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was when transaction name is like SomeService.someMethod and Oracle does not accept '.' in savepoint names. On the other hand, MSSQL limits savepoint name to 32 characters which was failing in tests for some transactional methods so this is what could work for both cases - return 'SavePoint' + transactionName.hashCode(). Trimming to 32 might cause some duplicated savepoint names from different methods/transactions so I think this is safer, unless we have to have human readable savepoint name for debug purposes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also (possibly?) the option of not using a save point name at all:
https://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#setSavepoint--

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense, since we don't refer to the savepoint name later, if I am not wrong.
Do you agree @dstepanov ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed to set savepoint without passing name and then don't need to deal with special chars and max length.

@dstepanov
Copy link
Contributor

Please also check the reactive TX manager

@radovanradic
Copy link
Contributor Author

Please also check the reactive TX manager

Updated logic for Hibernate transaction manager, reactive currently throwing nestedTxNotSupported() exception.

* @return true if exception is thrown for unsupported operation
*/
protected boolean isUnsupportedOperation(Exception exception) {
if (exception instanceof SQLFeatureNotSupportedException) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R2DBC wouldn't throw JDBC exceptions. Maybe Oracle will do it, because it's based on it but otherwise it's not expected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, moved back code from AbstractDefaultTransactionOperations into classes that will use this check.

Copy link

sonarqubecloud bot commented Aug 5, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
66.7% Coverage on New Code (required ≥ 70%)

See analysis details on SonarCloud

@radovanradic radovanradic merged commit 9fdf0e9 into 4.8.x Aug 5, 2024
50 of 51 checks passed
@radovanradic radovanradic deleted the nested-trans branch August 5, 2024 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants