Bug 1073082

Summary: [GSS] (6.2.x) HHH-8983 Database drivers may attach warnings to statement handles and these may accumulate and consume significant memory
Product: [JBoss] JBoss Enterprise Application Platform 6 Reporter: Brett Meyer <brmeyer>
Component: HibernateAssignee: Brett Meyer <brmeyer>
Status: CLOSED CURRENTRELEASE QA Contact: Zbyněk Roubalík <zroubali>
Severity: high Docs Contact: Lucas Costi <lcosti>
Priority: medium    
Version: 6.2.0CC: bmaxwell, cdewolf, lcosti, msimka, sfikes, theute
Target Milestone: CR2   
Target Release: EAP 6.2.3   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
When using `java.sql.Timestamp` types against a Sybase `datetime` type, Sybase attaches warning objects to the statement handles used by `insert`, `update`, and `query`. In situations where inserts or updates are batched, the accumulation of the warning objects can be significant, and if these statements remained cached, the memory usage can grow significantly. This issue was fixed modifying the JDBC coordinator implementation to log and clear the warnings so they are not retained in memory.
Story Points: ---
Clone Of: 1070423 Environment:
Last Closed: 2014-06-09 12:47:56 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1070423    
Bug Blocks: 1067532, 1070424, 1073094    

Description Brett Meyer 2014-03-05 17:49:01 UTC
+++ This bug was initially created as a clone of Bug #1070423 +++

Description of problem:
When using Timestamp types with underlying Sybase datetime mappings, Sybase' later drivers report a warning. In the case of batch updates which impact many rows, these warnings can add up to significant memory use.

It's desirable to have Hibernate log any warnings attached to a JDBC Connection, rather than hiding them from users. Further, it is critical to clear these warnings from the statement handles to free memory.

Version-Release number of selected component (if applicable):
EAP 6.2.0 and Hibernate 4.2.7.SP1.Final

How reproducible:
Consistently

Steps to Reproduce:
1. Column map in *.hbm.xml: <property name="date" type="timestamp" column="EVENT_DATE" />
2. Underlying type in the generated table will be Sybase 'datetime'
3. Perform an insert or update (batching many inserts or update magnifies the problem)
4. In the debugger, access the statement handle and there will be warnings on it (I never found a simple way to access the handle directly in code). Alternately, stop the testcase (using the debugger or cosole read() to pause the execution - e.g. in the tearDown() metho) and extract a heap dump. In Eclipse MAT with the heap open, you can use the OQL query: 'select * from com.sybase.jdbc4.jdbc.SybPreparedStatement'. You can then sort the result by the 'Retained Heap' column and expand and see that the top of the list is the _warning member which presents the head of a list chain of SQLWarning objects. Right click _warning, select "Show Retained Set" and click Finish on the dialog to see the chained objects.

Note that I didn't find a simple way to get to the raw com.sybase.jdbc4.jdbc.SybPreparedStatement handles.

Actual results:
Memory accumulates on the underlying Sybase statement handle in the _warnings member: _warning: java.sql.SQLWarning@...

The warnings (when there are multiple due to batching) are chained together by the SQLWarning objects.

Expected results:
The warnings should be cleared at minimum and optionally logged (if logged, this must be configurable as in the case of this Sybase scenario a high volume of logging would occur).

Additional info:

--- Additional comment from Brett Meyer on 2014-02-27 10:37:29 EST ---

Included in EAP 6.3.0's Hibernate ORM 4.2.9.Final upgrade

--- Additional comment from Brett Meyer on 2014-02-27 10:56:43 EST ---

https://hibernate.atlassian.net/browse/HHH-8983

Comment 3 Martin Simka 2014-05-12 12:41:53 UTC
verified on EAP 6.2.3.CP.CR2