Retrieving BLOB and CLOB columns

391 views
Skip to first unread message

timjohnc...@gmail.com

unread,
Jun 19, 2013, 3:44:13 AM6/19/13
to jooq...@googlegroups.com
I am a new user to JOOQ but have a question about retrieving BLOB and CLOB columns (I understand that there is not full support for LOBs, and that's fine)

When I query a table with a CLOB column

ResultQuery<Record> q = // setup a query
for (Result<Record> r : q.fetch()) {
    java.sql.Clob c = r.getValue("CLOB_COLUMN", java.sql.Clob.class);
}

I get an error telling me that oracle.sql.CLOB cannot be converted to java.sql.Clob. But oracle.sql.CLOB implements java.sql.Clob.

In the ConvertAll class if after all the checks have been performed before failing the conversion could you check if the two types are compatible with Class.isAssignableFrom(Class) ?

I can just retrieve the value as an Object for the time being and cast it myself to java.sql.Clob but feels like the conversion system should handle this case for me.

Thanks,
Tim

Lukas Eder

unread,
Jun 20, 2013, 3:33:17 AM6/20/13
to jooq...@googlegroups.com
Hi Tim,

I am a new user to JOOQ but have a question about retrieving BLOB and CLOB columns (I understand that there is not full support for LOBs, and that's fine)

When I query a table with a CLOB column

ResultQuery<Record> q = // setup a query
for (Result<Record> r : q.fetch()) {
    java.sql.Clob c = r.getValue("CLOB_COLUMN", java.sql.Clob.class);
}

I get an error telling me that oracle.sql.CLOB cannot be converted to java.sql.Clob. But oracle.sql.CLOB implements java.sql.Clob.

So, in order to get an oracle.sql.CLOB type, I suspect that you have used "plain SQL" to generate your query?

ResultQuery<Record> q = // setup a query with plain SQL?
 
That case indeed isn't covered by integration tests, which it should. I have registered #2534 for this:

Given the fact that jOOQ currently doesn't expose actual LOB types, this is probably a bug. I'll have to see how this could be fixed.

In the ConvertAll class if after all the checks have been performed before failing the conversion could you check if the two types are compatible with Class.isAssignableFrom(Class) ?

Yes, that's a good idea, too. In fact, this check could be made very early. I have registered #2535 for this:
 
I can just retrieve the value as an Object for the time being and cast it myself to java.sql.Clob but feels like the conversion system should handle this case for me.

Absolutely! Thanks for reporting

Cheers
Lukas

Lukas Eder

unread,
Jun 22, 2013, 3:29:32 AM6/22/13
to jooq...@googlegroups.com



2013/6/20 Lukas Eder <lukas...@gmail.com>

Hi Tim,

2013/6/19 <timjohnc...@gmail.com>

I am a new user to JOOQ but have a question about retrieving BLOB and CLOB columns (I understand that there is not full support for LOBs, and that's fine)

When I query a table with a CLOB column

ResultQuery<Record> q = // setup a query
for (Result<Record> r : q.fetch()) {
    java.sql.Clob c = r.getValue("CLOB_COLUMN", java.sql.Clob.class);
}

I get an error telling me that oracle.sql.CLOB cannot be converted to java.sql.Clob. But oracle.sql.CLOB implements java.sql.Clob.

So, in order to get an oracle.sql.CLOB type, I suspect that you have used "plain SQL" to generate your query?

ResultQuery<Record> q = // setup a query with plain SQL?
 
That case indeed isn't covered by integration tests, which it should. I have registered #2534 for this:

Given the fact that jOOQ currently doesn't expose actual LOB types, this is probably a bug. I'll have to see how this could be fixed.

In the ConvertAll class if after all the checks have been performed before failing the conversion could you check if the two types are compatible with Class.isAssignableFrom(Class) ?

Yes, that's a good idea, too. In fact, this check could be made very early. I have registered #2535 for this:

#2535 is implemented in Github master and will be available in the next 3.1.0-SNAPSHOT, today:

Cheers
Lukas

Tim Carpenter

unread,
Jun 26, 2013, 8:20:38 PM6/26/13
to jooq...@googlegroups.com
Hi Lucas,

Yes, the Query is created using "plain SQL", DSL.field("column_name") etc

Thanks a lot for putting the in the casting fix so quickly.

Cheers,
Tim

Lukas Eder

unread,
Jul 4, 2013, 10:12:04 AM7/4/13
to jooq...@googlegroups.com, Tim Carpenter
Hi Tim,

I've added a failing integration test for your issue:

I have to check how this can be fixed, as LOB types shouldn't leak through jOOQ, even when using plain SQL. See also the other related discussion here:

Upcasting should now be possible via the 3.1 fix #2535:

As a workaround, you can let jOOQ transform LOBs into String / byte[] by specifying:

DSL.field("clob_column", String.class)
DSL.field("clob_column", byte[].class)

Cheers
Lukas


2013/6/27 Tim Carpenter <timjohnc...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Lukas Eder

unread,
Sep 20, 2013, 7:20:34 AM9/20/13
to jooq...@googlegroups.com
Hello,

This is now fixed in jOOQ 3.2. When no type information is available, jOOQ will try to "unlob" all LOBs fetched from ResultSet.getObject() and return byte[] or String values for consistency with the rest of the API.
This change is committed and will be pushed to GitHub master in a larger push.

Cheers
Lukas


2013/7/4 Lukas Eder <lukas...@gmail.com>
Reply all
Reply to author
Forward
0 new messages