[ 
https://issues.apache.org/jira/browse/OPENJPA-1699?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12887491#action_12887491
 ] 

Fay Wang commented on OPENJPA-1699:
-----------------------------------

In the case of very large lob, DB2 JCC driver will automatically use 
progressive streaming to retrieve the Lob data. With progressiveStreaming, the 
inputStream retrieved (see red below) must be materialized before the next 
iteration of call to rs.next().

ResultSet rs = pstmt.executeQuery(...);
while (rs.next()) {
    InputStream is = rs.getBinaryInputStream(1);
    writeToFile(is);
}
rs.close();

However, in OpenJPA, we iterate through the whole resultSet and set the 
InputStream to respective entities:
ResultSet rs = pstmt.executeQuery(...);
while (rs.next()) {
    InputStream is = rs.getBinaryInputStream(1);
    entity.setInputStream(is);
}
rs.close();
...

        Once the entity is returned from OpenJPA, the application will get Lob 
Closed exception when trying to process the InputStream:

writeToFile(entity.getInputStream()); <== Lob is closed Exception

The work around is to  force fullyMaterializedLobData to true (see below) in 
the url, so that the DB2 JCC driver will materialize the whole Lob data into 
memory before returning to the application:
 
<property name="openjpa.ConnectionProperties"
value="DriverClassName=com.ibm.db2.jcc.DB2Driver,Url=jdbc:db2://localhost:50000/demodb:fullyMaterializeLobData=true;progressiveStreaming=NO;,Username=db2user,Password=passw0rd"
 />

> Streaming Lob support in DB2
> ----------------------------
>
>                 Key: OPENJPA-1699
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1699
>             Project: OpenJPA
>          Issue Type: New Feature
>          Components: jdbc
>    Affects Versions: 2.0.0
>            Reporter: Fay Wang
>            Assignee: Fay Wang
>             Fix For: 2.1.0
>
>
> Streaming Lob support in DB2

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to