I don't know why IBM's code does this, but here's what I found with tealwren's help:
I supposed if you have a many-to-one relationship in your collection (and AutoCommit = true), you'll see a function sequence error. I set autocommit to false (based upon your post) and lo-and-behold the function-sequence error is gone.
The error occurs when it does the following.
Hibernate goes to process a list. It goes through the list until it hits a many-to-one. At that point, it generates a new statement searching for the ID. (if there are a lot, you'll run into the n+1 problem, but fortunately for us, it will cache them and just do the matching in memory).
It processes this second statement successfully, and it adds it to the results:
Code:
results.add( getResultColumnOrRow(row, rs, session) ); // Line 178 of the Loader.class of 2.03
When it goes to run rs.next():
Code:
for ( count=0; count<maxRows && rs.next(); count++ ) { // line 151 of the Loader.class of 2.03
it blows the Function Sequence Error.
This really doesn't make sense to me, because this is query only. I think it's a bug in IBM's code. Hibernate does an excellent job of cleaning up the statements and result sets.
From the javadoc for JDBC Connection.setAutoCommit
Quote:
...The commit occurs when the statement completes or the next execute occurs, whichever comes first. In the case of statements returning a ResultSet object, the statement completes when the last row of the ResultSet object has been retrieved or the ResultSet object has been closed. In advanced cases, a single statement may return multiple results as well as output parameter values. In these cases, the commit occurs when all results and output parameter values have been retrieved.
I think it's caused by a bug in IBM's code. I have a CLI trace that shows the outer statement being committed when it should have been the inner statement that was committed. I'll try to send them a PMR.
My environment was:
Win2K (or AIX) it happened on both:
( DBMS NAME="DB2/NT", Version="07.02.0003", Fixpack="0x23040105" )
Hibernate 2.03
Using COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource