Re: ResultSet.getClob() causing problems when used with JPA's @Lob - Mailing list pgsql-jdbc

From Andreas Joseph Krogh
Subject Re: ResultSet.getClob() causing problems when used with JPA's @Lob
Date
Msg-id 4D524A75.2090305@officenet.no
Whole thread Raw
In response to Re: ResultSet.getClob() causing problems when used with JPA's @Lob  (Kris Jurka <books@ejurka.com>)
Responses Re: ResultSet.getClob() causing problems when used with JPA's @Lob  (Oliver Jowett <oliver@opencloud.com>)
Re: ResultSet.getClob() causing problems when used with JPA's @Lob  (Radosław Smogura <rsmogura@softperience.eu>)
List pgsql-jdbc
On 02/09/2011 01:20 AM, Kris Jurka wrote:
>
>
> On Mon, 7 Feb 2011, Andreas Joseph Krogh wrote:
>
>> It's not clear to me why the JDBC-driver for PG shouldn't just use
>> rs.getString() internally for getClob() calls? Requiring
>> special-handling in Hibernate for dealing with Strings by setting an
>> obscure property just doesn't seem right. And I don't want to set a
>> property to handle CLOB which might affect how I use BLOBs.
>>
>
> The problem is that we have no idea what someone might want to do with a
> CLOB after they've fetched it.  You're coming from the idea that all
> they want to do is read it and copy the data out to a String.  From that
> perspective it's not hard to have a Clob wrapper around a String, but
> what happens when they say clob.setString(13, "data")?  Are we going to
> try and figure out what row of what table that varchar column is coming
> from and do a partial update on it?

The javadoc for clob.setString(index, data) says:
----------------------------------------
Writes the given Java String to the CLOB value that this Clob object
designates at the position pos. The string will overwrite the existing
characters in the Clob object starting at the position pos. If the end
of the Clob value is reached while writing the given string, then the
length of the Clob value will be increased to accomodate the extra
characters.

Note: If the value specified for pos is greater then the length+1 of the
CLOB value then the behavior is undefined. Some JDBC drivers may throw a
SQLException while other drivers may support this operation.

Parameters:
pos - the position at which to start writing to the CLOB value that this
Clob object represents; The first position is 1
str - the string to be written to the CLOB value that this Clob designates
----------------------------------------

So, I think clob.setString(index, data) should behave just like
StringBuilder.insert(int offset, String str) except overwrite existing
data instead of moving the characters above the position.

--
Andreas Joseph Krogh <andreak@officenet.no>
Senior Software Developer / CTO
Public key: http://home.officenet.no/~andreak/public_key.asc
------------------------+---------------------------------------------+
OfficeNet AS            | The most difficult thing in the world is to |
Rosenholmveien 25       | know how to do a thing and to watch         |
1414 Trollåsen          | somebody else doing it wrong, without       |
NORWAY                  | comment.                                    |
Org.nr: NO 981 479 076  |                                             |
                        |                                             |
Tlf:    +47 24 15 38 90 |                                             |
Fax:    +47 24 15 38 91 |                                             |
Mobile: +47 909  56 963 |                                             |
------------------------+---------------------------------------------+

pgsql-jdbc by date:

Previous
From: Lew
Date:
Subject: Re: ResultSet.getClob() causing problems when used with JPA's @Lob
Next
From: Radosław Smogura
Date:
Subject: Re: UDT arrays