Subject | Re: [Firebird-Java] Problem with Scrollable Resultset and ResultSetHoldability |
---|---|
Author | Roman Rokytskyy |
Post date | 2010-04-22T11:56:08Z |
> We have a quite common scenario:Why don't you use two sessions then?
> We like to loop over a large resultset using cursors, modify data
> and commit them in chunks, i.e. perform a commit of the modified
> data after each 1000 result.
> In addition we are using hibernate.
> Our first problem was that ResultSet are created with the defaultShould throw exception before, maybe there is some Hibernate caching
> ResultSetHoldability=CLOSE_CURSORS_AT_COMMIT
> So the cursor would be closed after the first commit.
> (It seemed to last some more commits and only crashed
> with an exception at the end).
there...
> The only way to change the ResultSetHoldability when usingThis parameter is for the applications that need this option by deafult
> hibernate seems to be to open the connection with a parameter
> like:
>
> ...
> properties.put("defaultResultSetHoldable", "");
>
> DriverManagerDataSource out = new DriverManagerDataSource();
> out.setJdbcUrl( jdbcUrl );
> out.setProperties( driverProps );
> Connection con = out.getConnection();
and cannot be changed to use appropriate JDBC API call.
> The ScrollableResultSets now worked fine.That's what the parameter is about - make all prepared statements
> However we got a lot of warnings like:
>
> Holdable result set must be scrollable.
>
> This warning is created in org.firebirdsql.jdbc.AbstractConnection
> public synchronized Statement createStatement(int resultSetType,
> int resultSetConcurrency, int resultSetHoldability) throws SQLException
>
> if (resultSetHoldability == FirebirdResultSet.HOLD_CURSORS_OVER_COMMIT&&
> resultSetType == ResultSet.TYPE_FORWARD_ONLY) {
>
> addWarning(new FBSQLWarning("Holdable result set must be scrollable."));
> resultSetType = ResultSet.TYPE_SCROLL_INSENSITIVE;
> }
>
> Since resultSetHoldability == FirebirdResultSet.HOLD_CURSORS_OVER_COMMIT&&
> resultSetType == ResultSet.TYPE_FORWARD_ONLY is now always true
> we ended with all PreparedStatements being scrollable !
> This is of course not wanted.
scrollable by default.
Those applications that are "clever" enough would use
Connection.prepareStatement(String, int, int, int) call and those values
will override the defaults.
> At the moment we have no idea to get our above described scenario to work.Use two sessions in Hibernate - it is also more memory efficient.
> We hope the somebody else may have solved this problem.
Firebird does not support the scrollable result sets, so we have to
fetch complete result set into memory first, in order provide the
holdability feature.
The only issue that might be with using two sessions, is that you might
require check your code if you use session-per-thread scenario. In this
case you have to open second session directly via Hibernate API and
ensure that you close the session afterwards.
Roman