Bug 1070423

Summary: [GSS] (6.3.0) 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: Stephen Fikes <sfikes>
Component: HibernateAssignee: Brett Meyer <brmeyer>
Status: CLOSED CURRENTRELEASE QA Contact: Zbyněk Roubalík <zroubali>
Severity: high Docs Contact: Russell Dickenson <rdickens>
Priority: medium    
Version: 6.2.0CC: dstephan, jmartisk, kkhan, msimka, myarboro, sgilda, smumford, theute
Target Milestone: DR2   
Target Release: EAP 6.3.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
In previous versions of JBoss EAP 6 it was found that database drivers could attach warnings to statement handles which could accumulate and consume significant amounts of memory. The issue presented when using Timestamp types with underlying Sybase `datetime` mappings. The warnings issued by later Sybase drivers could begin to exaggerate the memory footprint in batch updates. This issue has been addressed in this release and no longer presents.
Story Points: ---
Clone Of:
: 1073082 (view as bug list) Environment:
Last Closed: 2014-06-28 15:25:32 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:    
Bug Blocks: 1063408, 1073082, 1087625    
Attachments:
Description Flags
Reproducer none

Description Stephen Fikes 2014-02-26 19:39:54 UTC
Created attachment 868158 [details]
Reproducer

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:

Comment 1 Brett Meyer 2014-02-27 15:37:29 UTC
Included in EAP 6.3.0's Hibernate ORM 4.2.9.Final upgrade

Comment 2 Brett Meyer 2014-02-27 15:56:43 UTC
https://hibernate.atlassian.net/browse/HHH-8983

Comment 3 Kabir Khan 2014-04-04 15:28:08 UTC
Fixed by upgrade -> ON_QA

Comment 4 Jan Martiska 2014-04-09 12:22:55 UTC
Verified in 6.3.0.ER1.

Comment 5 sgilda 2014-05-12 19:44:49 UTC
Changed <literal></literal> tags in Doc Text to ticks (`) to fix Bug 1096865