Skip to content

Commit 21b62db

Browse files
mc1arkedreab8
authored andcommitted
HHH-18325: Prevent comparison between proxied and non-proxied statements
Some JDBC connection pools create a dynamic reflective Proxy wrapper around connections in the pool, plus the generated statements and the result sets those statements create, with the proxies allowing for methods calls to be intercepted by the connection pool for the purposes of returning items to the pool when they're released rather than destroying the underlying database connection. Tomcat's JDBC pool implementation does not correctly wrap the full chain of objects, meaning the raw Statement can be retrieved from a ResultSet rather than returning the proxied statement. This results in the ResourceRegistry cache attempting to store both the proxied Statement and the non-proxied Statement in its cache, but encountering an exception when the HashMap encounters two entries with the same HashCode and then attempts to differentiate them with an `equals` call which Tomcat's wrapper expects both instances to be proxied connections. To overcome this issue in Tomcat, as well as any other pool implementation which may use Proxy classes but leak the un-proxied entries, the original PreparedStatement used to create the ResultSet is being passed into the GeneratedValuesHelper for passing into the ResourceRegistry, rather than the GeneratedValues helper attempting to extract the Statement from the ResultSet.
1 parent a14f46a commit 21b62db

File tree

2 files changed

+2428
-0
lines changed

2 files changed

+2428
-0
lines changed

hibernate-core/src/main/java/org/hibernate/generator/values/internal/GeneratedValuesHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class GeneratedValuesHelper {
6464
* for the specified {@link ResultSet}.
6565
*
6666
* @param resultSet The result set from which to extract the generated values
67+
* @param statement The prepared statement the result set was generated from
6768
* @param persister The entity type which we're reading the generated values for
6869
* @param session The session
6970
*
@@ -114,6 +115,7 @@ public static GeneratedValues getGeneratedValues(
114115
* using the {@link JdbcValuesMappingProducer} provided in input.
115116
*
116117
* @param resultSet the result set containing the generated values
118+
* @param statement The prepared statement the result set was generated from
117119
* @param persister the current entity persister
118120
* @param mappingProducer the mapping producer to use when reading generated values
119121
* @param session the current session

0 commit comments

Comments
 (0)