Issue Details (XML | Word | Printable)

Key: HHH-1312
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Gail Badner
Reporter: Michael Samblanet
Votes: 4
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
Hibernate Core

Unclosed ResultSet when using Identity

Created: 22/Dec/05 12:26 PM   Updated: 18/Oct/07 01:25 AM
Component/s: core
Affects Version/s: 3.1 rc2, 3.1 rc3, 3.1
Fix Version/s: 3.2.6, 3.3.0.CR1

Time Tracking:
Not Specified

Environment:
JBoss 4.0.3SP1
Hibernate 3.1rc2
Java 1.5.0_06
MSSQLServer 2000


 Description  « Hide
The code around AbstractEntityPersister.java line 1969 obtains a result set using GetGeneratedKeysHelper.getGeneratedKey
but the result set is never closed by this function nor the functions it calls. The issue was exposed by the
message below in JBoss 4.0.3 SP1.

This is an EJB3 application on JBoss using MSSQLServer 2000 and we are persisting an object with a primary key using an
identity data type.

A review of the Hibernate 3.1 source code seems to indicate it has the same issue.

11:29:30,817 WARN [WrappedConnection] Closing a result set you left open! Please close it yourself.
java.lang.Throwable: STACKTRACE
        at org.jboss.resource.adapter.jdbc.WrappedStatement.registerResultSet(WrappedStatement.java:572)
        at org.jboss.resource.adapter.jdbc.WrappedStatement.getGeneratedKeys(WrappedStatement.java:501)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.hibernate.util.GetGeneratedKeysHelper.getGeneratedKey(GetGeneratedKeysHelper.java:59)
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:1969)
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2404)
        at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:37)
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
        at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:269)
        at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
        at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:101)
        at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
        at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
        at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
        at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:590)
        at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:568)
        at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:130)
        at org.jboss.ejb3.entity.InjectedEntityManager.persist(InjectedEntityManager.java:97)
        <snip>


 All   Comments   Work Log   Change History   FishEye      Sort Order: Ascending order - Click to sort in descending order
Gavin King added a comment - 22/Dec/05 01:30 PM
Well, I don't want to get in an argument with Adrian, but in fact JDBC does not usually ask you to close ResultSets. I would be inclined to blame this on the JBoss JCA layer.

http://java.sun.com/j2se/1.4.2/docs/api/java/sql/ResultSet.html#close()

Well, anyway, we could be more "hygenic" here.

Eric Molitor added a comment - 13/Jun/06 02:12 PM
There is the possibility of leaking resources with a poorly implemented JDBC driver when resultsets are not properly closed. (So the hygenic cleanup would be greatly appreciated.)

To disable this behavior in JBoss open up the *-DS.xml file that you are using for Hibernate and set <track-statements>true</track-statements> to false. (Or just comment it out.)

Christian Gruber added a comment - 20/Aug/07 03:17 AM
Hi!

I'd also vote for closing the ResultSet, since
- hygiene is never a bad thing ;-)
- for bulk inserts with MySQL, this is a big memory leak

When I alter IdentityGenerator.GetGeneratedKeysDelegate.executeAndExtract() so that the ResultSet from GetGeneratedKeysHelper.getGeneratedKey(insert) is closed in a finally block, the memory leak vanishes (this applies to Hibernate 3.2.4). I don't know whether this is a specific problem of the MySQL JDBC driver (I use version 5.0.5), but as the additional code does not seem to hurt, I'd suggest to put it into the next Hibernate version.

Greetings,
Christian

Gail Badner added a comment - 18/Oct/07 01:25 AM
Thanks, Christian. I made the change as you suggested and checked that the ResultSet was property closed in the debugger. This should take care of the memory leak.

Fixed in trunk / 3.2 .