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

Rollback to or release of savepoint fails with ClassCastException #328

Closed
basdebakker opened this issue Feb 2, 2023 · 3 comments · Fixed by #331
Closed

Rollback to or release of savepoint fails with ClassCastException #328

basdebakker opened this issue Feb 2, 2023 · 3 comments · Fixed by #331
Assignees
Labels
bug Something isn't working

Comments

@basdebakker
Copy link

Describe the bug

Calling Connection.rollback(savepoint) or Connection.releaseSavepoint(savepoint) with a savepoint that was returned by Connection.setSavepoint() will fail with a ClassCastException.

Expected Behavior

No exception, instead the operation should succeed as it does when not using the wrapper library.

What plugins are used? What other connection properties were set?

None

Current Behavior

Exception in thread "main" java.lang.ClassCastException: class software.amazon.jdbc.wrapper.SavepointWrapper cannot be cast to class org.postgresql.jdbc.PSQLSavepoint (software.amazon.jdbc.wrapper.SavepointWrapper and org.postgresql.jdbc.PSQLSavepoint are in unnamed module of loader 'app')
	at org.postgresql.jdbc.PgConnection.rollback(PgConnection.java:1809)
	at software.amazon.jdbc.wrapper.ConnectionWrapper.lambda$rollback$39(ConnectionWrapper.java:678)
	at software.amazon.jdbc.util.WrapperUtils.lambda$runWithPlugins$1(WrapperUtils.java:169)
	at software.amazon.jdbc.plugin.DefaultConnectionPlugin.execute(DefaultConnectionPlugin.java:98)
	at software.amazon.jdbc.ConnectionPluginManager.lambda$execute$3(ConnectionPluginManager.java:327)
	at software.amazon.jdbc.ConnectionPluginManager.lambda$makePluginChainFunc$0(ConnectionPluginManager.java:267)
	at software.amazon.jdbc.ConnectionPluginManager.executeWithSubscribedPlugins(ConnectionPluginManager.java:249)
	at software.amazon.jdbc.ConnectionPluginManager.execute(ConnectionPluginManager.java:324)
	at software.amazon.jdbc.util.WrapperUtils.executeWithPlugins(WrapperUtils.java:226)
	at software.amazon.jdbc.util.WrapperUtils.runWithPlugins(WrapperUtils.java:162)
	at software.amazon.jdbc.wrapper.ConnectionWrapper.rollback(ConnectionWrapper.java:672)
	at AwsWrapperTest.main(AwsWrapperTest.java:9)

Reproduction Steps

Run code below, using your own values for the parameters to DriverManager.getConnection.

import java.sql.*;

public class AwsWrapperTest {

    public static void main(String[] args) throws SQLException {
        Connection connection = DriverManager.getConnection("jdbc:aws-wrapper:postgresql://localhost:49153/postgres", "username", "password");
        connection.setAutoCommit(false);
        Savepoint savepoint = connection.setSavepoint();
        connection.rollback(savepoint);
//        connection.releaseSavepoint(savepoint); // fails too when used instead of previous line
    }
}

Possible Solution

No response

Additional Information/Context

PostgreSQL version 15.1.

PostgreSQL JDBC driver "org.postgresql:postgresql:42.5.2"

The AWS Advanced JDBC Driver version used

1.0.1

JDK version used

openjdk version "17.0.3" 2022-04-19 OpenJDK Runtime Environment Temurin-17.0.3+7 (build 17.0.3+7) OpenJDK 64-Bit Server VM Temurin-17.0.3+7 (build 17.0.3+7, mixed mode, sharing)

Operating System and version

Windows 11

@basdebakker basdebakker added the bug Something isn't working label Feb 2, 2023
@davecramer
Copy link
Contributor

Thanks for the report!

@karenc-bq karenc-bq self-assigned this Feb 2, 2023
karenc-bq added a commit that referenced this issue Feb 3, 2023
Unwrap Savepoint objects when passing them in as parameters, fixes #328
@karenc-bq
Copy link
Contributor

Hi @basdebakker, this issue was addressed in PR #331, can you please checkout the snapshot build and let us know if the issue persists? Thank you.

@basdebakker
Copy link
Author

I can confirm that aws-advanced-jdbc-wrapper-1.0.2-20230203.234503-12.jar fixes my issue. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants