-
Notifications
You must be signed in to change notification settings - Fork 49
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
Distinct ClientPreparedStatement objects incorrectly have same hashCode and match with equals() #308
Comments
Appears to work - thanks @sergiyvamz! When should we expect 1.1.2 to be released? What is the release schedule for the driver? |
@sergiyvamz friendly bump! if you don't have the answer that's fine, but I just want to have a contingency plan for our own software release if we're not going to get this fix in an official version before our deadlines |
@buitcj we will get back to you ASAP with an answer. |
Hello @buitcj, we will be including an additional fix before we release an updated driver. We are planning to release 1.1.2 early next week. Does this align with your deadlines? Thanks, Matthew |
@hsuamz Yes it does. Thanks for the update |
Hi @buitcj, version 1.1.2 of the driver has been released, thank you for your patience. |
Describe the bug
Distinct
ClientPreparedStatement
s sharing aConnectionProxy
will all use thehashCode()
andequals()
of theConnectionProxy
and therefore will all have the same hash code and be equals via theequals()
call.This is a problem not only because fundamentally the objects are different so they should have different hash codes and not be equal, but also because when using the AWS Aurora MySQL driver with Hibernate 5, the
ClientPreparedStatement
s will be registered inResourceRegistryStandardImpl
here https://github.com/hibernate/hibernate-orm/blob/main/hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/ResourceRegistryStandardImpl.java#L87 . This code will throw an exception when theStatement
(key) was already registered. Multiple different statements with the samehashCode()
that are equal via theequals()
will cause this problem.Expected Behavior
Multiple
ClientPreparedStatement
s using the sameConnectionProxy
should have different hash code values and not be equal viaequals()
Current Behavior
Normally, Hibernate code will throw an exception when the
Statement
(key) was already registered. It detects this by seeing if the key already exists in its map. Using the AWS Aurora MySQL driver, multiple different statements with the samehashCode()
that are equal via theequals()
will cause a "JDBC Statement already registered" even if theStatement
s are not the same.Reproduction Steps
Using the same Hibernate
Session
, callprepareQueryStatement()
with two differentStatement
s that use different SQL queries.Expected: Successful registration of the two
Statement
sActual: First
ClientPreparedStatement
registers successfully but the second registration has anHibernateException
thrown fromResourceRegistryStandardImpl
with messageJDBC Statement already registered
Possible Solution
One possible solution is to simply not let the proxy directly execute
equals()
andhashCode()
and instead defer to the underlying Statement.src/main/user-impl/java/com/mysql/cj/jdbc/ha/ConnectionProxy.java
implementsinvoke()
(https://github.com/awslabs/aws-mysql-jdbc/blob/main/src/main/user-impl/java/com/mysql/cj/jdbc/ha/ConnectionProxy.java#L312) which will detect if the method isequals
orhashCode
(https://github.com/awslabs/aws-mysql-jdbc/blob/main/src/main/user-impl/java/com/mysql/cj/jdbc/ha/ConnectionProxy.java#L296) and if so, it uses the implementation of theConnectionProxy
instead of the implementation of the underlying object (https://github.com/awslabs/aws-mysql-jdbc/blob/main/src/main/user-impl/java/com/mysql/cj/jdbc/ha/ConnectionProxy.java#L267). In this case, the underlying object is theClientPreparedStatement
. Two differentClientPreparedStatement
objects that share the sameConnectionProxy
will be equal because they share the same hash code andequals()
will evaluate to true.Additional Information/Context
No response
The AWS JDBC Driver for MySQL version used
1.1.1 (and 1.1.0)
JDK version used
1.8
Operating System and version
MacOS Monterey 12.3.1
The text was updated successfully, but these errors were encountered: