pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
ResultSet.getClob() causing problems when used with JPA's @Lob
36+ messages / 7 participants
[nested] [flat]

* ResultSet.getClob() causing problems when used with JPA's @Lob
@ 2011-02-06 23:01 Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 08:11 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2016-07-20 11:51 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  0 siblings, 2 replies; 36+ messages in thread

From: Andreas Joseph Krogh @ 2011-02-06 23:01 UTC (permalink / raw)
  To: pgsql-jdbc

Hi.

I have a varchar-column in a table which maps to a field (of type String) in a 
JPA-entity. When marking that String-property with the JPA @Lob-annotation, 
using Hibernate as my JPA-provider, it stops working as expected when using 
PostgreSQL (works as expected on Oracle and SQL Server). The problem is that 
Hibernate, correctly, calls ResultSet.getClob() but PG internally calls 
getLong(), which obviously won't work with varchar-types, resulting in:

Caused by: org.postgresql.util.PSQLException: Bad value for type long : Hei
        at 
org.postgresql.jdbc2.AbstractJdbc2ResultSet.toLong(AbstractJdbc2ResultSet.java:2796)
        at 
org.postgresql.jdbc2.AbstractJdbc2ResultSet.getLong(AbstractJdbc2ResultSet.java:2019)
        at org.postgresql.jdbc4.Jdbc4ResultSet.getClob(Jdbc4ResultSet.java:43)
        at 
org.postgresql.jdbc2.AbstractJdbc2ResultSet.getClob(AbstractJdbc2ResultSet.java:384)
        at 
org.hibernate.type.descriptor.sql.ClobTypeDescriptor$4.doExtract(ClobTypeDescriptor.java:104)

After googling around I see this issue has come up before:
http://archives.postgresql.org/pgsql-jdbc/2010-02/msg00004.php

One is encurraged to use ResultSet.getString() instead. Hm, well - being at 
Hibernate's mercy here, I don't really have that luxury. So, is PG's JDBC-
driver going to fix this flaw (IMNSHO it is a flaw) or is there consensus in the 
PG-community that clobs are special and are not to be treated as 
Strings/varchars?

-- 
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 |                                             |
------------------------+---------------------------------------------+



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
@ 2011-02-07 08:11 ` Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 20:50   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  1 sibling, 1 reply; 36+ messages in thread

From: Radosław Smogura @ 2011-02-07 08:11 UTC (permalink / raw)
  To: pgsql-jdbc; +Cc: Andreas Joseph Krogh <andreak@officenet.no>

Hi,
PGSQL doesn't have CLOB type, instead JDBC uses LOB, but PGSQL doesn't have 
"clear" lob field type. It uses in table column with type OID, and supporting 
table for storing large objects.

Look at bug submited by me 
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4617
Should be fixed in 3.6.1 release.

Kind regards,
Radosław Smogura
http://softperience.eu

Andreas Joseph Krogh <andreak@officenet.no> Monday 07 February 2011 00:01:21
> Hi.
> 
> I have a varchar-column in a table which maps to a field (of type String)
> in a JPA-entity. When marking that String-property with the JPA
> @Lob-annotation, using Hibernate as my JPA-provider, it stops working as
> expected when using PostgreSQL (works as expected on Oracle and SQL
> Server). The problem is that Hibernate, correctly, calls
> ResultSet.getClob() but PG internally calls getLong(), which obviously
> won't work with varchar-types, resulting in:
> 
> Caused by: org.postgresql.util.PSQLException: Bad value for type long : Hei
>         at
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.toLong(AbstractJdbc2ResultSet.j
> ava:2796) at
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.getLong(AbstractJdbc2ResultSet.
> java:2019) at
> org.postgresql.jdbc4.Jdbc4ResultSet.getClob(Jdbc4ResultSet.java:43) at
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.getClob(AbstractJdbc2ResultSet.
> java:384) at
> org.hibernate.type.descriptor.sql.ClobTypeDescriptor$4.doExtract(ClobTypeDe
> scriptor.java:104)
> 
> After googling around I see this issue has come up before:
> http://archives.postgresql.org/pgsql-jdbc/2010-02/msg00004.php
> 
> One is encurraged to use ResultSet.getString() instead. Hm, well - being at
> Hibernate's mercy here, I don't really have that luxury. So, is PG's JDBC-
> driver going to fix this flaw (IMNSHO it is a flaw) or is there consensus
> in the PG-community that clobs are special and are not to be treated as
> Strings/varchars?



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 08:11 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
@ 2011-02-07 20:50   ` Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 21:38     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-09 00:20     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Kris Jurka <books@ejurka.com>
  0 siblings, 2 replies; 36+ messages in thread

From: Andreas Joseph Krogh @ 2011-02-07 20:50 UTC (permalink / raw)
  To: pgsql-jdbc

On 02/07/2011 09:11 AM, Radosław Smogura wrote:
> Hi,
> PGSQL doesn't have CLOB type, instead JDBC uses LOB, but PGSQL doesn't
have
> "clear" lob field type. It uses in table column with type OID, and
supporting
> table for storing large objects.
>
> Look at bug submited by me
> http://opensource.atlassian.com/projects/hibernate/browse/HHH-4617
> Should be fixed in 3.6.1 release.

I'm experiencing this with 3.6.1 so whatever that issue fixes,
MaterializedClobType (which is the default type Hibernate uses when it
sees @Lob on String-types) still uses ClobTypeDescriptor, which again
has this code:

protected X doExtract(ResultSet rs, String name, WrapperOptions options)
throws SQLException {
	return javaTypeDescriptor.wrap( rs.getClob( name ), options );
}

And it should be able to call rs.getClob().

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.

-- 
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 |                                             |
------------------------+---------------------------------------------+



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 08:11 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 20:50   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
@ 2011-02-07 21:38     ` Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 23:25       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  1 sibling, 1 reply; 36+ messages in thread

From: Radosław Smogura @ 2011-02-07 21:38 UTC (permalink / raw)
  To: pgsql-jdbc; +Cc: Andreas Joseph Krogh <andreak@officenet.no>

PostgreSQL doesn't have field type CLOB, nor BLOB. 

If eveny it would be possible for driver to read CLOB from varchar, driver 
will be unable to set proper value when calling UPDATE or INSTERT. It is due 
to internal way how PSQL deals with those values.

I know drivers supports custom casting, but casting from varchar to clob is 
implicite prohibted in JDBC. If you look at B-6 table x indicates possible 
casting. There is no x, nor X on varchar cross clob

Kind regards,
Radosław Smogura

Andreas Joseph Krogh <andreak@officenet.no> Monday 07 February 2011 21:50:10
> On 02/07/2011 09:11 AM, Radosław Smogura wrote:
> > Hi,
> > PGSQL doesn't have CLOB type, instead JDBC uses LOB, but PGSQL doesn't
> 
> have
> 
> > "clear" lob field type. It uses in table column with type OID, and
> 
> supporting
> 
> > table for storing large objects.
> > 
> > Look at bug submited by me
> > http://opensource.atlassian.com/projects/hibernate/browse/HHH-4617
> > Should be fixed in 3.6.1 release.
> 
> I'm experiencing this with 3.6.1 so whatever that issue fixes,
> MaterializedClobType (which is the default type Hibernate uses when it
> sees @Lob on String-types) still uses ClobTypeDescriptor, which again
> has this code:
> 
> protected X doExtract(ResultSet rs, String name, WrapperOptions options)
> throws SQLException {
> 	return javaTypeDescriptor.wrap( rs.getClob( name ), options );
> }
> 
> And it should be able to call rs.getClob().
> 
> 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.



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 08:11 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 20:50   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 21:38     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
@ 2011-02-07 23:25       ` Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-08 00:53         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
  0 siblings, 1 reply; 36+ messages in thread

From: Andreas Joseph Krogh @ 2011-02-07 23:25 UTC (permalink / raw)
  To: pgsql-jdbc

On 02/07/2011 10:38 PM, Radosław Smogura wrote:
> PostgreSQL doesn't have field type CLOB, nor BLOB. 

I know that.

> If eveny it would be possible for driver to read CLOB from varchar, driver 
> will be unable to set proper value when calling UPDATE or INSTERT. It is due 
> to internal way how PSQL deals with those values.

Isn't the whole concept of CLOB just a bi-product of old proprietary
database-design where some RDBMS'es are unable to store arbitrary long
varchars? What properties do CLOBs have that varchars don't, except
being large? I don't understand why CLOBs can't be treated like text in
the PG-driver as PG handles large Strings just fine in
varchar/text-columns. If a DBA has for some reason defined a scale, say
VARCHAR(10), on a column and tries to store a CLOB in it, well - his
problem; He should get an Exception from PG.

> I know drivers supports custom casting, but casting from varchar to clob is 
> implicite prohibted in JDBC. If you look at B-6 table x indicates possible 
> casting. There is no x, nor X on varchar cross clob

Does it not make sense to you to be able to cast a *character large
object* to a *variable length character*-type and visa versa?

If the only argument is spec-complience I'm not getting it...

-- 
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 |                                             |
------------------------+---------------------------------------------+



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 08:11 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 20:50   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 21:38     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 23:25       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
@ 2011-02-08 00:53         ` Oliver Jowett <oliver@opencloud.com>
  2011-02-08 09:02           ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  0 siblings, 1 reply; 36+ messages in thread

From: Oliver Jowett @ 2011-02-08 00:53 UTC (permalink / raw)
  To: pgsql-jdbc; +Cc: andreak@officenet.no

On 08/02/11 12:25, Andreas Joseph Krogh wrote:
> On 02/07/2011 10:38 PM, Radosław Smogura wrote:
>> PostgreSQL doesn't have field type CLOB, nor BLOB. 
> 
> I know that.
> 
>> If eveny it would be possible for driver to read CLOB from varchar, driver 
>> will be unable to set proper value when calling UPDATE or INSTERT. It is due 
>> to internal way how PSQL deals with those values.
> 
> Isn't the whole concept of CLOB just a bi-product of old proprietary
> database-design where some RDBMS'es are unable to store arbitrary long
> varchars? What properties do CLOBs have that varchars don't, except
> being large? I don't understand why CLOBs can't be treated like text in
> the PG-driver as PG handles large Strings just fine in
> varchar/text-columns. If a DBA has for some reason defined a scale, say
> VARCHAR(10), on a column and tries to store a CLOB in it, well - his
> problem; He should get an Exception from PG.

The different property is that clobs are mapped to OIDs that reference
an externally-stored LOB. So at the most basic "what do I get from the
server?" level they're different to varchar - the column type is an OID,
not varchar, so you have to send/receive OID values not strings and
perform a separate step to manage the data referenced by the OID.

They're mostly superceded by bytea/text, but they do still have some
properties that mean they do not behave identically (e.g. they are
essentially pass-by-reference, not pass-by-value; and you can modify
parts of them in-place without passing around the whole value).

>> I know drivers supports custom casting, but casting from varchar to clob is 
>> implicite prohibted in JDBC. If you look at B-6 table x indicates possible 
>> casting. There is no x, nor X on varchar cross clob
> 
> Does it not make sense to you to be able to cast a *character large
> object* to a *variable length character*-type and visa versa?
> 
> If the only argument is spec-complience I'm not getting it...

Conceivably, the driver could notice that a column is a varchar and
expose it via a different implementation of the clob interface that
doesn't try to interpret the value as an OID identifying an underlying
LOB. But that's not currently done because it's not one of the required
JDBC conversions (so if you expect that behavior from an arbitrary
driver you're already on shaky ground) and there's been no requests for
it before this that I can remember offhand. Also, the reverse conversion
isn't going to work, as mentioned above, so I don't know how useful it'd
be to you (the driver knows it got a varchar in a resultset, but in
general it won't know that when you said PreparedStatement.setClob() you
actually meant "please turn this into a varchar and insert that, instead
of creating a LOB and inserting the OID as you usually would"). You
could make it a big connection-wide toggle that said whether to
interpret clobs as LOBs or varchars, I suppose, but that's rather a big
hammer to fix what is arguably a problem in your persistence layer. (For
example, why can't you tell Hibernate exactly the same thing - "please
interpret my character LOBs as varchars" - which would be presumably be
useful to more than just the postgresql driver?)

The fundamental question here is "why are you trying to map a varchar to
a Clob?" .. As you say, clobs are mostly redundant anyway. Given that
your schema uses varchar, why don't you just use the varchar-style
accessors? It's not unreasonable to expect your access method to match
the underlying schema, surely.

Oliver



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 08:11 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 20:50   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 21:38     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 23:25       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-08 00:53         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
@ 2011-02-08 09:02           ` Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-08 10:35             ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
  0 siblings, 1 reply; 36+ messages in thread

From: Andreas Joseph Krogh @ 2011-02-08 09:02 UTC (permalink / raw)
  To: pgsql-jdbc

På tirsdag 08. februar 2011 kl 01:53:23 skrev "Oliver Jowett" <oliver@opencloud.com>:
> On 08/02/11 12:25, Andreas Joseph Krogh wrote:
> > On 02/07/2011 10:38 PM, Radosław Smogura wrote:
> >> PostgreSQL doesn't have field type CLOB, nor BLOB. 
> > 
> > I know that.
> > 
> >> If eveny it would be possible for driver to read CLOB from varchar, driver 
> >> will be unable to set proper value when calling UPDATE or INSTERT. It is due 
> >> to internal way how PSQL deals with those values.
> > 
> > Isn't the whole concept of CLOB just a bi-product of old proprietary
> > database-design where some RDBMS'es are unable to store arbitrary long
> > varchars? What properties do CLOBs have that varchars don't, except
> > being large? I don't understand why CLOBs can't be treated like text in
> > the PG-driver as PG handles large Strings just fine in
> > varchar/text-columns. If a DBA has for some reason defined a scale, say
> > VARCHAR(10), on a column and tries to store a CLOB in it, well - his
> > problem; He should get an Exception from PG.
> 
> The different property is that clobs are mapped to OIDs that reference
> an externally-stored LOB. So at the most basic "what do I get from the
> server?" level they're different to varchar - the column type is an OID,
> not varchar, so you have to send/receive OID values not strings and
> perform a separate step to manage the data referenced by the OID.
> 
> They're mostly superceded by bytea/text, but they do still have some
> properties that mean they do not behave identically (e.g. they are
> essentially pass-by-reference, not pass-by-value; and you can modify
> parts of them in-place without passing around the whole value).

Firstly; My issue here only affects CLOBs, not BLOBs.
Secondly; I'm not trying to be anal here, just trying to understand the arguments.
Thirdly; Didn't we just agree on that PG doesn't have CLOBs? If PG doesn't have CLOBs, how can it map CLOBs to OIDs? Under what circumstances would PG need an OID to map a *C*LOB? Are you suggesting to store CLOBs as bytea? Is anyone doing this?

> >> I know drivers supports custom casting, but casting from varchar to clob is 
> >> implicite prohibted in JDBC. If you look at B-6 table x indicates possible 
> >> casting. There is no x, nor X on varchar cross clob
> > 
> > Does it not make sense to you to be able to cast a *character large
> > object* to a *variable length character*-type and visa versa?
> > 
> > If the only argument is spec-complience I'm not getting it...
> 
> Conceivably, the driver could notice that a column is a varchar and
> expose it via a different implementation of the clob interface that
> doesn't try to interpret the value as an OID identifying an underlying
> LOB. But that's not currently done because it's not one of the required
> JDBC conversions (so if you expect that behavior from an arbitrary
> driver you're already on shaky ground) and there's been no requests for
> it before this that I can remember offhand. Also, the reverse conversion
> isn't going to work, as mentioned above, so I don't know how useful it'd
> be to you (the driver knows it got a varchar in a resultset, but in
> general it won't know that when you said PreparedStatement.setClob() you
> actually meant "please turn this into a varchar and insert that, instead
> of creating a LOB and inserting the OID as you usually would"). You
> could make it a big connection-wide toggle that said whether to
> interpret clobs as LOBs or varchars, I suppose, but that's rather a big
> hammer to fix what is arguably a problem in your persistence layer. (For
> example, why can't you tell Hibernate exactly the same thing - "please
> interpret my character LOBs as varchars" - which would be presumably be
> useful to more than just the postgresql driver?)

All this stuff sounds like an implementation detail to me. The programmer using JDBC should, IMO, be able to use rs.setClob() to varchar/text-columns transparently as there's no reason to treat it differently than setString().

> The fundamental question here is "why are you trying to map a varchar to
> a Clob?" .. As you say, clobs are mostly redundant anyway. Given that
> your schema uses varchar, why don't you just use the varchar-style
> accessors? It's not unreasonable to expect your access method to match
> the underlying schema, surely.

The reason I map the String-property as @Lob (which, by default, makes Hibernate use setClob()) is for interoperability with other DBs, like Oracle, which require this annotation in order to be able to store Strings which are over 4000 chars long. These properties are stored in Oracle as CLOB and in PG as VARCHAR.

--
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 |                                             |
------------------------+---------------------------------------------+



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 08:11 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 20:50   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 21:38     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 23:25       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-08 00:53         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
  2011-02-08 09:02           ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
@ 2011-02-08 10:35             ` Oliver Jowett <oliver@opencloud.com>
  2011-02-08 11:34               ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  0 siblings, 1 reply; 36+ messages in thread

From: Oliver Jowett @ 2011-02-08 10:35 UTC (permalink / raw)
  To: Andreas Joseph Krogh <andreak@officenet.no>; +Cc: pgsql-jdbc

Andreas Joseph Krogh wrote:

> Firstly; My issue here only affects CLOBs, not BLOBs.

BLOB-vs-bytea is essentially the same issue as CLOB-vs-varchar, FWIW. If 
you tried to use the BLOB interface on a bytea column or vice versa, 
you'd see similar problems, because bytea is not a BLOB, regardless of 
the fact that they're both ways of storing large binary data.

> Thirdly; Didn't we just agree on that PG doesn't have CLOBs? If PG doesn't have CLOBs, how can it map CLOBs to OIDs? Under what circumstances would PG need an OID to map a *C*LOB? Are you suggesting to store CLOBs as bytea? Is anyone doing this?

No, I don't think we agreed on that. The PG driver certainly does have 
something that is a CLOB - it is a column that contains an OID 
referencing a separate LO that contains character data. The server 
itself doesn't know about that mapping, but when you're working at the 
JDBC level, you do need to be aware of the mapping.

(One way to look at it is to pretend that "clob" is spelled "oid" in 
your schema)

> All this stuff sounds like an implementation detail to me. The programmer using JDBC should, IMO, be able to use rs.setClob() to varchar/text-columns transparently as there's no reason to treat it differently than setString().

Why do you assume this? JDBC's CLOB is not the same type as VARCHAR, and 
JDBC doesn't require that they're interchangeable.

And, in fact, the postgresql driver's mapping of CLOB is not 
interchangeable with VARCHAR, which is the root of your problem..

>> The fundamental question here is "why are you trying to map a varchar to
>> a Clob?" .. As you say, clobs are mostly redundant anyway. Given that
>> your schema uses varchar, why don't you just use the varchar-style
>> accessors? It's not unreasonable to expect your access method to match
>> the underlying schema, surely.
> 
> The reason I map the String-property as @Lob (which, by default, makes Hibernate use setClob()) is for interoperability with other DBs, like Oracle, which require this annotation in order to be able to store Strings which are over 4000 chars long. These properties are stored in Oracle as CLOB and in PG as VARCHAR.

Your problem here is that by using the JDBC driver's set/getClob() 
methods (indirectly via Hibernate), you are saying "I want to treat this 
type as a CLOB"; and a CLOB is mapped by the postgresql driver to the 
*oid* type, *not* the varchar type you are using in your schema.

So you have a mismatch between your schema and how you are trying to 
access it. Is there some reason your schema can't use oid here, as the 
driver requires?

When you're using something like Hibernate you have three layers involved:

1) your application layer, which is dealing in terms of Java objects
2) your persistence layer, which handles the mapping of the Java objects 
to a SQL schema, perhaps in a database-specific or schema-specific way 
(as customized by annotations etc)
3) the JDBC layer, which handles the database-specific parts of taking a 
SQL query expressed via the JDBC API and giving it to the database.

The JDBC layer (3) really is quite a simple mapping. It does not have 
any knowledge of how you want to handle the data up at layer (1) - it 
just does specifically what is asked of it. When Hibernate calls, e.g., 
setClob() or getClob() it is explicitly asking the driver to interpret 
that parameter/column as a JDBC CLOB, which in the postgresql world 
means "a LO containing character data referenced by OID". If that 
interpretation doesn't match your schema, that's not a problem with the 
driver - it means that layer (2) doesn't have the right mapping set up. 
Putting knowledge in layer (3) about how to map your particular schema 
to the particular datatypes you want is really the wrong place for it - 
the JDBC API just doesn't provide a place to put that information.

(TBH, I'd think the simplest solution would be to just teach Hibernate's 
postgresql dialect to map String-with-@Lob to the text type - the clob 
support in the driver is limited at best)

Oliver



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 08:11 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 20:50   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 21:38     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 23:25       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-08 00:53         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
  2011-02-08 09:02           ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-08 10:35             ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
@ 2011-02-08 11:34               ` Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-08 12:30                 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
  2011-02-08 12:31                 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
  2011-02-08 15:18                 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-09 03:23                 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Lew <noone@lewscanon.com>
  0 siblings, 4 replies; 36+ messages in thread

From: Andreas Joseph Krogh @ 2011-02-08 11:34 UTC (permalink / raw)
  To: pgsql-jdbc

På tirsdag 08. februar 2011 kl 11:35:37 skrev du:
> Andreas Joseph Krogh wrote:
> 
> > Firstly; My issue here only affects CLOBs, not BLOBs.
> 
> BLOB-vs-bytea is essentially the same issue as CLOB-vs-varchar, FWIW. If 
> you tried to use the BLOB interface on a bytea column or vice versa, 
> you'd see similar problems, because bytea is not a BLOB, regardless of 
> the fact that they're both ways of storing large binary data.
> 
> > Thirdly; Didn't we just agree on that PG doesn't have CLOBs? If PG doesn't have CLOBs, how can it map CLOBs to OIDs? Under what circumstances would PG need an OID to map a *C*LOB? Are you suggesting to store CLOBs as bytea? Is anyone doing this?
> 
> No, I don't think we agreed on that.

I meant on the server-side.

> The PG driver certainly does have 
> something that is a CLOB - it is a column that contains an OID 
> referencing a separate LO that contains character data. The server 
> itself doesn't know about that mapping, but when you're working at the 
> JDBC level, you do need to be aware of the mapping.
> 
> (One way to look at it is to pretend that "clob" is spelled "oid" in 
> your schema)

And what benefits does having a LO referencing character-data gives you instead of just using varchar/text? I don't see any motivation for using a LO?

> > All this stuff sounds like an implementation detail to me. The programmer using JDBC should, IMO, be able to use rs.setClob() to varchar/text-columns transparently as there's no reason to treat it differently than setString().
> 
> Why do you assume this? JDBC's CLOB is not the same type as VARCHAR, and 
> JDBC doesn't require that they're interchangeable.
> 
> And, in fact, the postgresql driver's mapping of CLOB is not 
> interchangeable with VARCHAR, which is the root of your problem..
> 
> >> The fundamental question here is "why are you trying to map a varchar to
> >> a Clob?" .. As you say, clobs are mostly redundant anyway. Given that
> >> your schema uses varchar, why don't you just use the varchar-style
> >> accessors? It's not unreasonable to expect your access method to match
> >> the underlying schema, surely.
> > 
> > The reason I map the String-property as @Lob (which, by default, makes Hibernate use setClob()) is for interoperability with other DBs, like Oracle, which require this annotation in order to be able to store Strings which are over 4000 chars long. These properties are stored in Oracle as CLOB and in PG as VARCHAR.
> 
> Your problem here is that by using the JDBC driver's set/getClob() 
> methods (indirectly via Hibernate), you are saying "I want to treat this 
> type as a CLOB"; and a CLOB is mapped by the postgresql driver to the 
> *oid* type, *not* the varchar type you are using in your schema.
> 
> So you have a mismatch between your schema and how you are trying to 
> access it. Is there some reason your schema can't use oid here, as the 
> driver requires?
> 
> When you're using something like Hibernate you have three layers involved:
> 
> 1) your application layer, which is dealing in terms of Java objects
> 2) your persistence layer, which handles the mapping of the Java objects 
> to a SQL schema, perhaps in a database-specific or schema-specific way 
> (as customized by annotations etc)
> 3) the JDBC layer, which handles the database-specific parts of taking a 
> SQL query expressed via the JDBC API and giving it to the database.
> 
> The JDBC layer (3) really is quite a simple mapping. It does not have 
> any knowledge of how you want to handle the data up at layer (1) - it 
> just does specifically what is asked of it. When Hibernate calls, e.g., 
> setClob() or getClob() it is explicitly asking the driver to interpret 
> that parameter/column as a JDBC CLOB, which in the postgresql world 
> means "a LO containing character data referenced by OID". If that 
> interpretation doesn't match your schema, that's not a problem with the 
> driver - it means that layer (2) doesn't have the right mapping set up. 
> Putting knowledge in layer (3) about how to map your particular schema 
> to the particular datatypes you want is really the wrong place for it - 
> the JDBC API just doesn't provide a place to put that information.
> 
> (TBH, I'd think the simplest solution would be to just teach Hibernate's 
> postgresql dialect to map String-with-@Lob to the text type - the clob 
> support in the driver is limited at best)

I hear over and over that PGs JDBC-driver wants to map CLOBs to OIDs but there really doesn't seem to be any good reasons for it (at least not that I can see). Why would I want to map my data as OID instead of varchar when the data is a JAVA-String? Is anyone using LO and the LO-api for storing large character-data? I think not. The @Lob annotation (which started this thread) is just there to help other DBs map the String-property correctly, I would love to get rid of it but need it to have my app work with Oracle. I also want other properties of varchar to work (LIKE-operator f.ex., which Oracle also support on CLOBs), and I don't know what the PG-LO type supports. Honestly; I don't see any reason to use LOs at all, neither for BLOB (where I use bytea) or CLOBs (where I use varchar).

I get around this problem in Hibernate by using this combination:

    @Column(name="my_name")
    @Lob
    @Type(type="org.hibernate.type.StringClobType")

...but the StringClobType is deprecated.

--
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 |                                             |
------------------------+---------------------------------------------+



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 08:11 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 20:50   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 21:38     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 23:25       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-08 00:53         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
  2011-02-08 09:02           ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-08 10:35             ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
  2011-02-08 11:34               ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
@ 2011-02-08 12:30                 ` Oliver Jowett <oliver@opencloud.com>
  3 siblings, 0 replies; 36+ messages in thread

From: Oliver Jowett @ 2011-02-08 12:30 UTC (permalink / raw)
  To: Andreas Joseph Krogh <andreak@officenet.no>; +Cc: pgsql-jdbc

Andreas Joseph Krogh wrote:

> I hear over and over that PGs JDBC-driver wants to map CLOBs to OIDs but there really doesn't seem to be any good reasons for it

It's mostly there for historical reasons - IIRC it dates back to the 
early 7.x days when you *had* to use LOs to store large data, because 
there was no such thing as the "text" or "bytea" type. There's really 
not much reason to use it in new code these days, as I said. But there's 
also not much reason to arbitrarily break compatibility with existing 
code that assumes the current behavior, just for the sake of your 
particular application.

I think that your efforts here might be more productively directed 
towards improving the Hibernate postgresql implementation so that it 
avoids using get/setClob() entirely.

Oliver



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 08:11 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 20:50   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 21:38     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 23:25       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-08 00:53         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
  2011-02-08 09:02           ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-08 10:35             ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
  2011-02-08 11:34               ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
@ 2011-02-08 12:31                 ` Oliver Jowett <oliver@opencloud.com>
  3 siblings, 0 replies; 36+ messages in thread

From: Oliver Jowett @ 2011-02-08 12:31 UTC (permalink / raw)
  To: Andreas Joseph Krogh <andreak@officenet.no>; +Cc: pgsql-jdbc

Andreas Joseph Krogh wrote:

> ...but the StringClobType is deprecated.

The obvious question here is "why?"

Oliver



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 08:11 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 20:50   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 21:38     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 23:25       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-08 00:53         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
  2011-02-08 09:02           ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-08 10:35             ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
  2011-02-08 11:34               ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
@ 2011-02-08 15:18                 ` Radosław Smogura <rsmogura@softperience.eu>
  3 siblings, 0 replies; 36+ messages in thread

From: Radosław Smogura @ 2011-02-08 15:18 UTC (permalink / raw)
  To: pgsql-jdbc; +Cc: Andreas Joseph Krogh <andreak@officenet.no>

Andreas Joseph Krogh <andreak@officenet.no> Tuesday 08 February 2011 12:34:19
> I hear over and over that PGs JDBC-driver wants to map CLOBs to OIDs but
> there really doesn't seem to be any good reasons for it (at least not that
> I can see). Why would I want to map my data as OID instead of varchar when
> the data is a JAVA-String? Is anyone using LO and the LO-api for storing
> large character-data? I think not. The @Lob annotation (which started this
> thread) is just there to help other DBs map the String-property correctly,
> I would love to get rid of it but need it to have my app work with Oracle.
> I also want other properties of varchar to work (LIKE-operator f.ex.,
> which Oracle also support on CLOBs), and I don't know what the PG-LO type
> supports. Honestly; I don't see any reason to use LOs at all, neither for
> BLOB (where I use bytea) or CLOBs (where I use varchar).

Actually there is good reason LOB are streamed. As it stands it's "large 
object", and need special treatment. This LO can be 1,2 or 16GB. If you will 
use bytea (it's impossible for such large objects) PGSQL sends all data in one 
message so, select * my_table_with_los will end with OutOfMemory. 2nd reason 
is that different communication is performed with LOBs, this is streaming 
mode, which is faster so you will not OOM your JVM. You need to understand 
that LO wasn't made to be something more then "fiele systems" in database for 
realy big files.

CLOBS are more historical, in days of XMLs, but historical applications still 
exists and sitll many systemes use plain flat files to exchange data.



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 08:11 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 20:50   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 21:38     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 23:25       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-08 00:53         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
  2011-02-08 09:02           ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-08 10:35             ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
  2011-02-08 11:34               ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
@ 2011-02-09 03:23                 ` Lew <noone@lewscanon.com>
  2011-02-10 07:39                   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  3 siblings, 1 reply; 36+ messages in thread

From: Lew @ 2011-02-09 03:23 UTC (permalink / raw)
  To: pgsql-jdbc

Andreas Joseph Krogh wrote:
> I get around this problem in Hibernate by using this combination:
>
>      @Column(name="my_name")
>      @Lob
>      @Type(type="org.hibernate.type.StringClobType")
>
> ...but the StringClobType is deprecated.
>

It really makes it so much easier to have a TEXT column mapped to a 'String'.

  @Entity public class Foo
  {
    @Id
    private String ident;
    private String somethingBackedByTEXT;
   ...
  }

FWIW, in a database like Oracle that does have CLOBs it's still a lot easier 
with Hibernate to map CLOBs to 'String' than to 'Clob', as I learned from 
experience.  Even the Hibernate documentation recommends against mapping to 
'Clob'.

-- 
Lew
Ceci n'est pas une fenêtre.
.___________.
|###] | [###|
|##/  | *\##|
|#/ * |   \#|
|#----|----#|
||    |  * ||
|o *  |    o|
|_____|_____|
|===========|



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 08:11 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 20:50   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 21:38     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 23:25       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-08 00:53         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
  2011-02-08 09:02           ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-08 10:35             ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
  2011-02-08 11:34               ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-09 03:23                 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Lew <noone@lewscanon.com>
@ 2011-02-10 07:39                   ` Andreas Joseph Krogh <andreak@officenet.no>
  0 siblings, 0 replies; 36+ messages in thread

From: Andreas Joseph Krogh @ 2011-02-10 07:39 UTC (permalink / raw)
  To: pgsql-jdbc

On 02/09/2011 04:23 AM, Lew wrote:
> Andreas Joseph Krogh wrote:
>> I get around this problem in Hibernate by using this combination:
>>
>>      @Column(name="my_name")
>>      @Lob
>>      @Type(type="org.hibernate.type.StringClobType")
>>
>> ...but the StringClobType is deprecated.
>>
> 
> It really makes it so much easier to have a TEXT column mapped to a
> 'String'.
> 
>  @Entity public class Foo
>  {
>    @Id
>    private String ident;
>    private String somethingBackedByTEXT;
>   ...
>  }
> 
> FWIW, in a database like Oracle that does have CLOBs it's still a lot
> easier with Hibernate to map CLOBs to 'String' than to 'Clob', as I
> learned from experience.  Even the Hibernate documentation recommends
> against mapping to 'Clob'.

Seems you missed the point

My mapping was like this, to a String-property

    @Column(name="my_name")
    @Lob
    @Type(type="org.hibernate.type.StringClobType")
    private String someLongDescription;

But I have to use @Lob in order to be able to persist this long String
in Oracle. With PG it works without the @Lob but then it's not portable.
The problem is that Hibernate uses ResultSet.setClob() regardless of the
DB-dialect when it sees @Lob on a String-type. This shouldn't be a
problem is the PG JDBC-driver implemented setClob as setString, but some
think that's not correct.

-- 
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 |                                             |
------------------------+---------------------------------------------+



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 08:11 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 20:50   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
@ 2011-02-09 00:20     ` Kris Jurka <books@ejurka.com>
  2011-02-09 08:04       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  1 sibling, 1 reply; 36+ messages in thread

From: Kris Jurka @ 2011-02-09 00:20 UTC (permalink / raw)
  To: Andreas Joseph Krogh <andreak@officenet.no>; +Cc: pgsql-jdbc



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?

Kris Jurka



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 08:11 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 20:50   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-09 00:20     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Kris Jurka <books@ejurka.com>
@ 2011-02-09 08:04       ` Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-09 09:40         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Oliver Jowett <oliver@opencloud.com>
  2011-02-10 18:24         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  0 siblings, 2 replies; 36+ messages in thread

From: Andreas Joseph Krogh @ 2011-02-09 08:04 UTC (permalink / raw)
  To: 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 |                                             |
------------------------+---------------------------------------------+



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 08:11 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 20:50   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-09 00:20     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Kris Jurka <books@ejurka.com>
  2011-02-09 08:04       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
@ 2011-02-09 09:40         ` Oliver Jowett <oliver@opencloud.com>
  1 sibling, 0 replies; 36+ messages in thread

From: Oliver Jowett @ 2011-02-09 09:40 UTC (permalink / raw)
  To: Andreas Joseph Krogh <andreak@officenet.no>; +Cc: pgsql-jdbc

Andreas Joseph Krogh wrote:
> On 02/09/2011 01:20 AM, Kris Jurka wrote:

>> 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?

> 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.

You really missed Kris' point here - the question is not "how should we 
modify the data?" but "how do we locate the data to modify in the first 
place?". Consider:

  SELECT somedatacolumn FROM sometable WHERE complex condition

Now you have a resultset with one column. It's a varchar. The caller 
calls ResultSet.getClob().setString(). What does the driver do? 
Synthesize an UPDATE statement? How? With what parameters?

Oliver



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-07 08:11 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Radosław Smogura <rsmogura@softperience.eu>
  2011-02-07 20:50   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2011-02-09 00:20     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Kris Jurka <books@ejurka.com>
  2011-02-09 08:04       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
@ 2011-02-10 18:24         ` Radosław Smogura <rsmogura@softperience.eu>
  1 sibling, 0 replies; 36+ messages in thread

From: Radosław Smogura @ 2011-02-10 18:24 UTC (permalink / raw)
  To: pgsql-jdbc; +Cc: Andreas Joseph Krogh <andreak@officenet.no>

After think, It is good idea to have CLOBS for VARCHARS, but to have any 
chance:
How do You create this CLOB? If your column will be null you are in trouble, 
as it will be impossible to call setClob(...) to set VARCHAR value. I mean 
everyting will work until you will set/change values only by retrivied Clob 
methods. You will be unable to set VARCHAR value with connection.createBlob, 
too

You will need to ensure your VARCHAR will not be NULL, and your JPA will use 
Clob.getter/Setter. 

Andreas Joseph Krogh <andreak@officenet.no> Wednesday 09 February 2011 
09:04:05
> 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.



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
@ 2016-07-20 11:51 ` Thomas Kellerer <spam_eater@gmx.net>
  2016-07-20 12:37   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-27 19:19   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  1 sibling, 2 replies; 36+ messages in thread

From: Thomas Kellerer @ 2016-07-20 11:51 UTC (permalink / raw)
  To: pgsql-jdbc

Andreas Joseph Krogh schrieb am 07.02.2011 um 00:01:
> I have a varchar-column in a table which maps to a field (of type String) in a 
> JPA-entity. When marking that String-property with the JPA @Lob-annotation, 
> using Hibernate as my JPA-provider, it stops working as expected when using 
> PostgreSQL (works as expected on Oracle and SQL Server). The problem is that 
> Hibernate, correctly, calls ResultSet.getClob() but PG internally calls 
> getLong(), which obviously won't work with varchar-types, resulting in:
> 
> Caused by: org.postgresql.util.PSQLException: Bad value for type long : Hei
>         at 
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.toLong(AbstractJdbc2ResultSet.java:2796)
>         at 
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.getLong(AbstractJdbc2ResultSet.java:2019)
>         at org.postgresql.jdbc4.Jdbc4ResultSet.getClob(Jdbc4ResultSet.java:43)
>         at 
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.getClob(AbstractJdbc2ResultSet.java:384)
>         at 
> org.hibernate.type.descriptor.sql.ClobTypeDescriptor$4.doExtract(ClobTypeDescriptor.java:104)
> 
> After googling around I see this issue has come up before:
> http://archives.postgresql.org/pgsql-jdbc/2010-02/msg00004.php
> 
> One is encurraged to use ResultSet.getString() instead. Hm, well - being at 
> Hibernate's mercy here, I don't really have that luxury. So, is PG's JDBC-
> driver going to fix this flaw (IMNSHO it is a flaw) or is there consensus in the 
> PG-community that clobs are special and are not to be treated as 
> Strings/varchars?


Is there anything new here? 
This still doesn't work with 9.4.1208

We are using Hibernate with an application that has to support Oracle and Postgres. 

For Oracle we have to use CLOB to store Strings longer then 4000 characters - which means we *have* to use CLOB. 
The Hibernate Entity is therefore annotated with @Lob and thus the whole thing fails with Postgres

So we are caught between a rock and a hard place: change to String and lose the ability to work with Oracle (which we can't) or stick with @Lob and lose the possibility to also support Postgres.

I think a connection parameter treatClobAsString=true would solve this problem - at least for us (and I think for most others that have this problem as well). 

Are there any plans for this? 

If not, is this something that would be accepted as a patch? 


Thomas





-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2016-07-20 11:51 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
@ 2016-07-20 12:37   ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-20 13:40     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  1 sibling, 1 reply; 36+ messages in thread

From: Vladimir Sitnikov @ 2016-07-20 12:37 UTC (permalink / raw)
  To: Thomas Kellerer <spam_eater@gmx.net>; pgsql-jdbc

>Is there anything new here?
>This still doesn't work with 9.4.1208

Nothing new here yet.

>So we are caught between a rock and a hard place

I feel your pain.

Technically the problem is pgjdbc does not have "String -> Clob" conversion
yet.

>Are there any plans for this?

I've not heard of those.

>If not, is this something that would be accepted as a patch?

I think so.
It should be possible to check the result column type and
create java.sql.Clob instance that would just work off the resulting string.

Special thank would go for a patch that would add JPA -> pgjdbc kind of
integration test to the regression suite.

Vladimir

^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2016-07-20 11:51 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-20 12:37   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
@ 2016-07-20 13:40     ` Thomas Kellerer <spam_eater@gmx.net>
  2016-07-20 13:52       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  0 siblings, 1 reply; 36+ messages in thread

From: Thomas Kellerer @ 2016-07-20 13:40 UTC (permalink / raw)
  To: pgsql-jdbc

Vladimir Sitnikov schrieb am 20.07.2016 um 14:37:
>>Is there anything new here?
>>This still doesn't work with 9.4.1208
> 
> Nothing new here yet.
> 
>>So we are caught between a rock and a hard place
> 
> I feel your pain.
> 
> Technically the problem is pgjdbc does not have "String -> Clob" conversion yet.
> 
>>Are there any plans for this?
> 
> I've not heard of those.
> 
>>If not, is this something that would be accepted as a patch?
> 
> I think so.
> It should be possible to check the result column type and create java.sql.Clob instance that would just work off the resulting string.

I don't think checking the column type is necessary (at least not for me).
If this option is enabled, then all calls to getClob() are simply "re-routed" to getString().





-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2016-07-20 11:51 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-20 12:37   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-20 13:40     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
@ 2016-07-20 13:52       ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-20 14:55         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  0 siblings, 1 reply; 36+ messages in thread

From: Vladimir Sitnikov @ 2016-07-20 13:52 UTC (permalink / raw)
  To: Thomas Kellerer <spam_eater@gmx.net>; pgsql-jdbc

1) AFAIK, Oracle allows to use getString/setString for clob columns when
using Oracle JDBC driver 10.2 or higher. Basically you set
SetBigStringTryClob=true
connection option and that is it.

2)
Thomas>I don't think checking the column type is necessary (at least not
for me).
Thomas>If this option is enabled, then all calls to getClob() are simply
"re-routed" to getString().

I'm afraid you miss the point.

In postgresql world, there's "large object API":
https://www.postgresql.org/docs/current/static/lo-interfaces.html
pgjdbc wraps that, so if you have a column of "oid" type, then you can
access the value via getClob and pgjdbc would reroute the calls to large
object API.

So getLong is not a mistake in getClob. getLong is here to retrieve the
value of "large object oid" (i.e. pointer). That is why column type is
crucial to tell if getClob is dealing with "large object API" or "just a
string".

Vladimir

^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2016-07-20 11:51 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-20 12:37   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-20 13:40     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-20 13:52       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
@ 2016-07-20 14:55         ` Thomas Kellerer <spam_eater@gmx.net>
  2016-07-20 15:47           ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  0 siblings, 1 reply; 36+ messages in thread

From: Thomas Kellerer @ 2016-07-20 14:55 UTC (permalink / raw)
  To: pgsql-jdbc

Vladimir Sitnikov schrieb am 20.07.2016 um 15:52:
> 2)
> Thomas>I don't think checking the column type is necessary (at least not for me).
> Thomas>If this option is enabled, then all calls to getClob() are simply "re-routed" to getString().
> 
> I'm afraid you miss the point.
> 
> In postgresql world, there's "large object API": https://www.postgresql.org/docs/current/static/lo-interfaces.html
> pgjdbc wraps that, so if you have a column of "oid" type, then you can access the value via getClob and pgjdbc would reroute the calls to large object API.

I am aware of the large object API but for the intended use case of "treatClobAsString=true" this would simply not support storing string values through large objects - and I doubt that any project that would actually use "treatClobAsString=true" would mix CLOBs as "large objects" and CLOBs as "text".

> So getLong is not a mistake in getClob. getLong is here to retrieve the value of "large object oid" (i.e. pointer). 
> That is why column type is crucial to tell if getClob is dealing with "large object API" or "just a string".

If we look at the use-case for this "override", I'm pretty sure there are (a lot) more people that could benefit from an unconditional getClob() == getString() then people that actually need the distinction because they store large text data as "large objects" (oid columns):

Thomas



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2016-07-20 11:51 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-20 12:37   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-20 13:40     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-20 13:52       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-20 14:55         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
@ 2016-07-20 15:47           ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  0 siblings, 0 replies; 36+ messages in thread

From: Vladimir Sitnikov @ 2016-07-20 15:47 UTC (permalink / raw)
  To: Thomas Kellerer <spam_eater@gmx.net>; pgsql-jdbc

Thomas> treatClobAsString

I do not find adding such a property is justified.
Adding random properties complicates behavior, it makes support harder and
it makes bugs more obscure.

Vladimir

^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2016-07-20 11:51 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
@ 2016-07-27 19:19   ` Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:58     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  1 sibling, 1 reply; 36+ messages in thread

From: Thomas Kellerer @ 2016-07-27 19:19 UTC (permalink / raw)
  To: pgsql-jdbc

Thomas Kellerer schrieb am 20.07.2016 um 13:51:
>> I have a varchar-column in a table which maps to a field (of type String) in a
>> JPA-entity. When marking that String-property with the JPA @Lob-annotation,
>> using Hibernate as my JPA-provider, it stops working as expected when using
>> PostgreSQL (works as expected on Oracle and SQL Server). The problem is that
>> Hibernate, correctly, calls ResultSet.getClob() but PG internally calls
>> getLong(), which obviously won't work with varchar-types, resulting in:
>>
>>
>> After googling around I see this issue has come up before:
>> http://archives.postgresql.org/pgsql-jdbc/2010-02/msg00004.php
>>
>> One is encurraged to use ResultSet.getString() instead. Hm, well - being at
>> Hibernate's mercy here, I don't really have that luxury. So, is PG's JDBC-
>> driver going to fix this flaw (IMNSHO it is a flaw) or is there consensus in the
>> PG-community that clobs are special and are not to be treated as
>> Strings/varchars?
>
>
> Is there anything new here?
> This still doesn't work with 9.4.1208
>
> We are using Hibernate with an application that has to support Oracle and Postgres.
>
> For Oracle we have to use CLOB to store Strings longer then 4000 characters - which means we *have* to use CLOB.
> The Hibernate Entity is therefore annotated with @Lob and thus the whole thing fails with Postgres
>
> So we are caught between a rock and a hard place: change to String and lose the ability to work with Oracle (which we can't)
>or stick with @Lob and lose the possibility to also support Postgres.
>

Please find attached a patch that does the following:

* An implementation of the java.sql.Clob interface based on a String
* An implementation of the java.sql.Blob interface based on a byte[]
*A modified PgResultSet that checks the column type in getClob() and getBlob() and
returns the approriate Lob implementation if the column is a varchar/text or bytea
column.

The methods to set a stream are not implemented yet though.

I did not extend AbstractBlobClob as that makes too many assumption that the
underlying Lob is a "large object" in the database and I would wind up overwriting
nearly all methods in there.

I did however create an AbstractBasicLob to re-use the check for the correct position. The assertPosition()
methods in there are a copy from AbstractBlobClob. If this is something that gets accepted, it might
make sense to derive AbstractBlobClob from AbstractBasicLob and keep the assertions in a single place.

I don't know if we also need support for creating empty Clobs based on Strings that can be filled later

I think something similar is needed for PgPreparedStatement as well, but I did not find a way to check
the type of a column the way it's done in PgResultSet. It seems that ParameterList.getTypeOIDs()
would provide that information, but I don't know how to use that. If someone points me in the right
direction I can add that as well.


Regards
Thomas

-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc

Attachments:

lob.patch (text/plain, 15.2K) download diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/AbstractBasicLob.java b/pgjdbc/src/main/java/org/postgresql/jdbc/AbstractBasicLob.java new file mode 100644 index 0000000..81b5ba1 --- /dev/null +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/AbstractBasicLob.java @@ -0,0 +1,45 @@ +/*------------------------------------------------------------------------- +* +* Copyright (c) 2005-2014, PostgreSQL Global Development Group +* +* +*------------------------------------------------------------------------- +*/ +package org.postgresql.jdbc; + +import java.sql.SQLException; +import org.postgresql.util.GT; +import org.postgresql.util.PSQLException; +import org.postgresql.util.PSQLState; + +public class AbstractBasicLob { + + /** + * Throws an exception if the pos value exceeds the max value by which the large object API can index. + * + * @param pos Position to write at. + * @throws SQLException if something goes wrong + */ + protected void assertPosition(long pos) throws SQLException { + assertPosition(pos, 0); + } + + /** + * Throws an exception if the pos value exceeds the max value by which the large object API can index. + * + * @param pos Position to write at. + * @param len number of bytes to write. + * @throws SQLException if something goes wrong + */ + protected void assertPosition(long pos, long len) throws SQLException { + if (pos < 1) { + throw new PSQLException(GT.tr("LOB positioning offsets start at 1."), + PSQLState.INVALID_PARAMETER_VALUE); + } + if (pos + len - 1 > Integer.MAX_VALUE) { + throw new PSQLException(GT.tr("PostgreSQL LOBs can only index to: {0}", Integer.MAX_VALUE), + PSQLState.INVALID_PARAMETER_VALUE); + } + } + +} diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/PgByteaBlob.java b/pgjdbc/src/main/java/org/postgresql/jdbc/PgByteaBlob.java new file mode 100644 index 0000000..d85cb75 --- /dev/null +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/PgByteaBlob.java @@ -0,0 +1,137 @@ +package org.postgresql.jdbc; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.sql.Blob; +import java.sql.SQLException; +import java.util.Arrays; + +/** + * + * @author Thomas Kellerer + */ +public class PgByteaBlob + extends AbstractBasicLob + implements java.sql.Blob { + + private byte[] content; + + public PgByteaBlob(byte[] content) { + this.content = content; + } + + @Override + public long length() + throws SQLException { + return content.length; + } + + @Override + public byte[] getBytes(long pos, int length) + throws SQLException { + + assertPosition(pos); + + return Arrays.copyOfRange(content, (int)(pos - 1), (int)length); + } + + public byte[] getBytes() + throws SQLException { + + return Arrays.copyOf(content, content.length); + } + + @Override + public InputStream getBinaryStream() + throws SQLException { + + return new ByteArrayInputStream(content); + } + + @Override + public long position(byte[] pattern, long start) + throws SQLException { + + assertPosition(start); + + for (int i=0; i < content.length; i++) { + int pi = 0; + while (content[i] == pattern[pi] && pi < pattern.length) { + pi ++; + } + if (pi == pattern.length) { + return i + 1; + } + } + return -1; + } + + @Override + public long position(Blob pattern, long start) + throws SQLException { + + byte[] toSearch = pattern.getBytes(1, (int)pattern.length()); + + return position(toSearch, start); + } + + @Override + public int setBytes(long pos, byte[] bytes) + throws SQLException { + + assertPosition(pos); + + return setBytes(pos, bytes, 0, bytes.length); + } + + @Override + public int setBytes(long pos, byte[] bytes, int offset, int len) + throws SQLException { + + if (bytes == null) { + return 0; + } + + assertPosition(pos); + + pos = pos - 1; + + if (pos + len > content.length) { + content = Arrays.copyOf(content, (int)pos + len); + } + + System.arraycopy(bytes, offset, content, (int)pos, len); + + return len; + } + + @Override + public OutputStream setBinaryStream(long pos) + throws SQLException { + + throw org.postgresql.Driver.notImplemented(this.getClass(), "setBinaryStream(long)"); + } + + @Override + public void truncate(long len) + throws SQLException { + + content = Arrays.copyOfRange(content, 0, (int)len); + } + + @Override + public void free() + throws SQLException { + + // nothing to do + } + + @Override + public InputStream getBinaryStream(long pos, long length) + throws SQLException { + + return new ByteArrayInputStream(content, (int)(pos - 1), (int)length); + } + +} diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java b/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java index 088f303..511056e 100644 --- a/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java @@ -420,6 +420,13 @@ public class PgResultSet implements ResultSet, org.postgresql.PGRefCursorResultS return null; } + switch (getSQLType(i)) { + case Types.BINARY: + case Types.VARBINARY: + case Types.LONGVARBINARY: + return new PgByteaBlob(getBytes(i)); + } + return makeBlob(getLong(i)); } @@ -474,6 +481,13 @@ public class PgResultSet implements ResultSet, org.postgresql.PGRefCursorResultS return null; } + switch (getSQLType(i)) { + case Types.CHAR: + case Types.VARCHAR: + case Types.LONGVARCHAR: + return new PgStringClob(getString(i)); + } + return makeClob(getLong(i)); } diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/PgStringClob.java b/pgjdbc/src/main/java/org/postgresql/jdbc/PgStringClob.java new file mode 100644 index 0000000..70245b2 --- /dev/null +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/PgStringClob.java @@ -0,0 +1,162 @@ +/*------------------------------------------------------------------------- +* +* Copyright (c) 2004-2015, PostgreSQL Global Development Group +* +* +*------------------------------------------------------------------------- +*/ +package org.postgresql.jdbc; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Reader; +import java.io.StringReader; +import java.io.UnsupportedEncodingException; +import java.io.Writer; +import java.sql.Clob; +import java.sql.SQLException; + +/** + * + * @author Thomas Kellerer + */ +public class PgStringClob + extends AbstractBasicLob + implements java.sql.Clob { + + private String content; + + public PgStringClob(String data) { + + this.content = data; + } + + @Override + public long length() + throws SQLException { + + return content.length(); + } + + @Override + public String getSubString(long pos, int length) + throws SQLException { + + assertPosition(pos); + + return content.substring((int)(pos - 1), (int)pos + length - 1); + } + + @Override + public Reader getCharacterStream() + throws SQLException { + + return new StringReader(content); + } + + @Override + public InputStream getAsciiStream() + throws SQLException { + + try { + return new ByteArrayInputStream(content.getBytes("UTF-8")); + } catch (UnsupportedEncodingException ex) { + // should not happen + throw new SQLException("UTF-8 not supported"); + } + } + + @Override + public long position(String searchstr, long start) + throws SQLException { + + assertPosition(start); + + return content.indexOf(searchstr, (int)start - 1) + 1; + } + + @Override + public long position(Clob searchstr, long start) + throws SQLException { + + assertPosition(start); + + String toSearch = searchstr.getSubString(1, (int)searchstr.length()); + return position(toSearch, start); + } + + @Override + public int setString(long pos, String str) + throws SQLException { + + assertPosition(pos); + + if (str == null) return 0; + + StringBuilder buffer = new StringBuilder(content.length()); + buffer.append(content.substring(0, (int)(pos - 1))); + buffer.append(str); + if (str.length() + (pos - 1) < content.length()) { + buffer.append(content.substring(str.length() + (int)(pos - 1))); + } + content = buffer.toString(); + return str.length(); + } + + @Override + public int setString(long pos, String str, int offset, int len) + throws SQLException { + + assertPosition(pos); + + if (str == null) { + return 0; + } + return setString(pos, str.substring(offset, offset + len)); + } + + @Override + public OutputStream setAsciiStream(long pos) + throws SQLException { + + throw org.postgresql.Driver.notImplemented(this.getClass(), "setAsciiStream(long)"); + } + + @Override + public Writer setCharacterStream(long pos) + throws SQLException { + + throw org.postgresql.Driver.notImplemented(this.getClass(), "setCharacterStream(long)"); + } + + @Override + public void truncate(long len) + throws SQLException { + + if (len > content.length()) { + // nothing to do + return; + } + content = content.substring(0, (int)len); + } + + @Override + public void free() + throws SQLException { + // nothing to do + } + + @Override + public Reader getCharacterStream(long pos, long length) + throws SQLException { + + return new StringReader(content.substring((int)(pos - 1), (int)length)); + } + + @Override + public String toString() { + return content; + } + +} diff --git a/pgjdbc/src/test/java/org/postgresql/jdbc/PgByteaBlobTest.java b/pgjdbc/src/test/java/org/postgresql/jdbc/PgByteaBlobTest.java new file mode 100644 index 0000000..de8a1f6 --- /dev/null +++ b/pgjdbc/src/test/java/org/postgresql/jdbc/PgByteaBlobTest.java @@ -0,0 +1,112 @@ +/*------------------------------------------------------------------------- +* +* Copyright (c) 2004-2015, PostgreSQL Global Development Group +* +* +*------------------------------------------------------------------------- +*/ +package org.postgresql.jdbc; + +import static junit.framework.TestCase.assertEquals; +import static org.junit.Assert.assertArrayEquals; +import org.junit.Test; + +/** + * + * @author Thomas Kellerer + */ +public class PgByteaBlobTest { + + public PgByteaBlobTest() { + } + + @Test + public void testLength() throws Exception { + byte[] data = new byte[]{1,2,3,4}; + PgByteaBlob blob = new PgByteaBlob(data); + assertEquals(data.length, blob.length()); + } + + @Test + public void testGetBytes() throws Exception { + byte[] data = new byte[]{1,2,3,4}; + PgByteaBlob blob = new PgByteaBlob(data); + assertArrayEquals(data, blob.getBytes(1, data.length)); + } + + @Test + public void testSetBytes1() throws Exception { + byte[] data = new byte[]{1,2,3,4}; + PgByteaBlob blob = new PgByteaBlob(data); + blob.setBytes(2,new byte[]{0,0}); + byte[] newData = blob.getBytes(); + assertEquals(4, newData.length); + assertEquals(1, newData[0]); + assertEquals(0, newData[1]); + assertEquals(0, newData[2]); + assertEquals(4, newData[3]); + + blob = new PgByteaBlob(data); + blob.setBytes(1,new byte[]{10,11,12,13,14,15,16}); + newData = blob.getBytes(); + assertEquals(7, newData.length); + for (int i=0; i < newData.length; i++) { + assertEquals(10 + i, newData[i]); + } + } + + @Test + public void testSetBytes2() throws Exception { + byte[] data = new byte[]{1,2,3,4}; + PgByteaBlob blob = new PgByteaBlob(data); + + byte[] data2 = new byte[] {1,2,3,4,5,6,7,8}; + blob.setBytes(1, data2, 4, 1); + byte[] current = blob.getBytes(); + assertEquals(data.length, current.length); + assertEquals(5, current[0]); + + byte[] data3 = new byte[] {10,11,12,13,14,15,16}; + blob = new PgByteaBlob(new byte[]{1,2,3,4}); + blob.setBytes(2, data3, 0, 7); + current = blob.getBytes(); + assertEquals(8, current.length); + assertEquals(1, current[0]); + for (int i=1; i < current.length; i++) { + assertEquals(10 + i - 1, current[i]); + } + } + + @Test + public void testPosition1() + throws Exception{ + + PgByteaBlob blob = new PgByteaBlob(new byte[]{1,2,3,4,5,6,7,8,9,10}); + long pos = blob.position(new byte[] { 3,4,5 }, 1); + assertEquals(3, pos); + + pos = blob.position(new byte[] {11,4,5}, 1); + assertEquals(-1, pos); + + pos = blob.position(new byte[] {1,2,3}, 3); + assertEquals(-1, pos); + + pos = blob.position(new byte[] {9,10}, 1); + assertEquals(9, pos); + + pos = blob.position(new byte[] {9,10}, 5); + assertEquals(9, pos); + + pos = blob.position(new byte[] {8,9,10}, 9); + assertEquals(-1, pos); + } + + @Test + public void testTruncate() throws Exception { + byte[] data = new byte[]{1,2,3,4}; + PgByteaBlob blob = new PgByteaBlob(data); + blob.truncate(2); + assertEquals(2, blob.length()); + } + +} diff --git a/pgjdbc/src/test/java/org/postgresql/jdbc/PgStringClobTest.java b/pgjdbc/src/test/java/org/postgresql/jdbc/PgStringClobTest.java new file mode 100644 index 0000000..a0affbd --- /dev/null +++ b/pgjdbc/src/test/java/org/postgresql/jdbc/PgStringClobTest.java @@ -0,0 +1,100 @@ +/*------------------------------------------------------------------------- +* +* Copyright (c) 2004-2015, PostgreSQL Global Development Group +* +* +*------------------------------------------------------------------------- +*/ +package org.postgresql.jdbc; + + +import static junit.framework.TestCase.*; +import org.junit.Test; + +/** + * + * @author Thomas Kellerer + */ +public class PgStringClobTest +{ + + public PgStringClobTest() + { + } + + @Test + public void testLength() + throws Exception + { + String data = "Hello, Clob"; + PgStringClob clob = new PgStringClob(data); + assertEquals(data.length(), clob.length()); + } + + @Test + public void testGetSubString() + throws Exception + { + String data = "Hello, Clob"; + PgStringClob clob = new PgStringClob(data); + String result = clob.getSubString(1, 5); + assertEquals("Hello", result); + } + + @Test + public void testPositionString() + throws Exception + { + String data = "Hello, Clob"; + PgStringClob clob = new PgStringClob(data); + long result = clob.position(",", 1); + assertEquals(data.indexOf(',') + 1, result); + } + + @Test + public void testPositionClob() + throws Exception + { + String data = "Hello, Clob"; + PgStringClob clob = new PgStringClob(data); + PgStringClob searchstr = new PgStringClob("Clob"); + long result = clob.position(searchstr, 1); + assertEquals(data.indexOf("Clob") + 1, result); + } + + @Test + public void testSetString1() + throws Exception + { + String data = "Hello, Clob"; + PgStringClob clob = new PgStringClob(data); + clob.setString(8, "World"); + assertEquals("Hello, World", clob.toString()); + } + + @Test + public void testSetString2() + throws Exception + { + } + + @Test + public void testTruncate() + throws Exception + { + String data = "Hello, Clob"; + PgStringClob clob = new PgStringClob(data); + clob.truncate(5); + assertEquals(5, clob.length()); + assertEquals("Hello", clob.toString()); + } + + @Test + public void testToString() + { + String data = "Hello, Clob"; + PgStringClob clob = new PgStringClob(data); + assertEquals(data, clob.toString()); + } + +}
^ permalink raw reply [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2016-07-20 11:51 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:19   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
@ 2016-07-27 19:58     ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-28 05:37       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-28 20:24       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  0 siblings, 2 replies; 36+ messages in thread

From: Vladimir Sitnikov @ 2016-07-27 19:58 UTC (permalink / raw)
  To: Thomas Kellerer <spam_eater@gmx.net>; pgsql-jdbc

Thomas,

Thanks for looking into this, however could you please file a github PR so
the system tests the change against different PostgreSQL / Java versions?

Could you add a test case that explores ResultSet.getClob as well?


I think something similar is needed for PgPreparedStatement as well, but I
> did not find a way to check
> the type of a column the way it's done in PgResultSet. It seems that
> ParameterList.getTypeOIDs()
> would provide that information, but I don't know how to use that. If
> someone points me in the right
> direction I can add that as well.


I'm not yet ready to answer that.

Vladimir

^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2016-07-20 11:51 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:19   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:58     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
@ 2016-07-28 05:37       ` Thomas Kellerer <spam_eater@gmx.net>
  2016-07-28 13:57         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  1 sibling, 1 reply; 36+ messages in thread

From: Thomas Kellerer @ 2016-07-28 05:37 UTC (permalink / raw)
  To: pgsql-jdbc

Vladimir Sitnikov schrieb am 27.07.2016 um 21:58:
> Thomas,
> 
> Thanks for looking into this, however could you please file a github PR so the system tests the change against different PostgreSQL / Java versions?


Sorry, I don't have a github account, so I can't do that. 

 
> Could you add a test case that explores ResultSet.getClob as well?

Yes, of course. 

Thomas



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2016-07-20 11:51 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:19   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:58     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-28 05:37       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
@ 2016-07-28 13:57         ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-28 20:23           ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  0 siblings, 1 reply; 36+ messages in thread

From: Vladimir Sitnikov @ 2016-07-28 13:57 UTC (permalink / raw)
  To: Thomas Kellerer <spam_eater@gmx.net>; +Cc: pgsql-jdbc

>
> > Thanks for looking into this, however could you please file a github PR
> so the system tests the change against different PostgreSQL / Java versions?
>
>
> Sorry, I don't have a github account, so I can't do that.
>
> I've created a PR with your changes. Tests work ok, however code style is
not in line with the project.
Here's the test report: https://travis-ci.org/pgjdbc/pgjdbc/builds/147963868

Can you fix checkstyle errors as well?
FYI: you can run `mvn checkstyle:check` to check the style locally.

Vladimir

^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2016-07-20 11:51 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:19   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:58     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-28 05:37       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-28 13:57         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
@ 2016-07-28 20:23           ` Thomas Kellerer <spam_eater@gmx.net>
  0 siblings, 0 replies; 36+ messages in thread

From: Thomas Kellerer @ 2016-07-28 20:23 UTC (permalink / raw)
  To: pgsql-jdbc

Vladimir Sitnikov schrieb am 28.07.2016 um 15:57:
>      > Thanks for looking into this, however could you please file a github PR so the system tests the change against different PostgreSQL / Java versions?
>
>
>     Sorry, I don't have a github account, so I can't do that.
>
> I've created a PR with your changes. Tests work ok, however code style is not in line with the project.
> Here's the test report: https://travis-ci.org/pgjdbc/pgjdbc/builds/147963868
>
> Can you fix checkstyle errors as well?
> FYI: you can run `mvn checkstyle:check` to check the style locally.
>
> Vladimir

Thanks.

Here is a new patch with formatting fixed and a test for PgResultSet

Thomas

-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc

Attachments:

lob.patch.2 (text/plain, 20.4K) download diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/AbstractBasicLob.java b/pgjdbc/src/main/java/org/postgresql/jdbc/AbstractBasicLob.java new file mode 100644 index 0000000..81b5ba1 --- /dev/null +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/AbstractBasicLob.java @@ -0,0 +1,45 @@ +/*------------------------------------------------------------------------- +* +* Copyright (c) 2005-2014, PostgreSQL Global Development Group +* +* +*------------------------------------------------------------------------- +*/ +package org.postgresql.jdbc; + +import java.sql.SQLException; +import org.postgresql.util.GT; +import org.postgresql.util.PSQLException; +import org.postgresql.util.PSQLState; + +public class AbstractBasicLob { + + /** + * Throws an exception if the pos value exceeds the max value by which the large object API can index. + * + * @param pos Position to write at. + * @throws SQLException if something goes wrong + */ + protected void assertPosition(long pos) throws SQLException { + assertPosition(pos, 0); + } + + /** + * Throws an exception if the pos value exceeds the max value by which the large object API can index. + * + * @param pos Position to write at. + * @param len number of bytes to write. + * @throws SQLException if something goes wrong + */ + protected void assertPosition(long pos, long len) throws SQLException { + if (pos < 1) { + throw new PSQLException(GT.tr("LOB positioning offsets start at 1."), + PSQLState.INVALID_PARAMETER_VALUE); + } + if (pos + len - 1 > Integer.MAX_VALUE) { + throw new PSQLException(GT.tr("PostgreSQL LOBs can only index to: {0}", Integer.MAX_VALUE), + PSQLState.INVALID_PARAMETER_VALUE); + } + } + +} diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/PgByteaBlob.java b/pgjdbc/src/main/java/org/postgresql/jdbc/PgByteaBlob.java new file mode 100644 index 0000000..36e6d8f --- /dev/null +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/PgByteaBlob.java @@ -0,0 +1,145 @@ +/*------------------------------------------------------------------------- +* +* Copyright (c) 2004-2015, PostgreSQL Global Development Group +* +* +*------------------------------------------------------------------------- + */ + +package org.postgresql.jdbc; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.sql.Blob; +import java.sql.SQLException; +import java.util.Arrays; + +/** + * + * @author Thomas Kellerer + */ +public class PgByteaBlob + extends AbstractBasicLob + implements java.sql.Blob { + + private byte[] content; + + public PgByteaBlob(byte[] content) { + this.content = content; + } + + @Override + public long length() + throws SQLException { + return content.length; + } + + @Override + public byte[] getBytes(long pos, int length) + throws SQLException { + + assertPosition(pos); + + return Arrays.copyOfRange(content, (int)(pos - 1), (int)length); + } + + public byte[] getBytes() + throws SQLException { + + return Arrays.copyOf(content, content.length); + } + + @Override + public InputStream getBinaryStream() + throws SQLException { + + return new ByteArrayInputStream(content); + } + + @Override + public long position(byte[] pattern, long start) + throws SQLException { + + assertPosition(start); + + for (int i = 0; i < content.length; i++) { + int pi = 0; + while (content[i] == pattern[pi] && pi < pattern.length) { + pi++; + } + if (pi == pattern.length) { + return i + 1; + } + } + return -1; + } + + @Override + public long position(Blob pattern, long start) + throws SQLException { + + byte[] toSearch = pattern.getBytes(1, (int)pattern.length()); + + return position(toSearch, start); + } + + @Override + public int setBytes(long pos, byte[] bytes) + throws SQLException { + + assertPosition(pos); + + return setBytes(pos, bytes, 0, bytes.length); + } + + @Override + public int setBytes(long pos, byte[] bytes, int offset, int len) + throws SQLException { + + if (bytes == null) { + return 0; + } + + assertPosition(pos); + + pos = pos - 1; + + if (pos + len > content.length) { + content = Arrays.copyOf(content, (int)pos + len); + } + + System.arraycopy(bytes, offset, content, (int)pos, len); + + return len; + } + + @Override + public OutputStream setBinaryStream(long pos) + throws SQLException { + + throw org.postgresql.Driver.notImplemented(this.getClass(), "setBinaryStream(long)"); + } + + @Override + public void truncate(long len) + throws SQLException { + + content = Arrays.copyOfRange(content, 0, (int)len); + } + + @Override + public void free() + throws SQLException { + + // nothing to do + } + + @Override + public InputStream getBinaryStream(long pos, long length) + throws SQLException { + + return new ByteArrayInputStream(content, (int)(pos - 1), (int)length); + } + +} diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java b/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java index 088f303..b81ecf8 100644 --- a/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java @@ -8,29 +8,6 @@ package org.postgresql.jdbc; -import org.postgresql.PGResultSetMetaData; -import org.postgresql.core.BaseConnection; -import org.postgresql.core.BaseStatement; -import org.postgresql.core.Encoding; -import org.postgresql.core.Field; -import org.postgresql.core.Oid; -import org.postgresql.core.Query; -import org.postgresql.core.ResultCursor; -import org.postgresql.core.ResultHandler; -import org.postgresql.core.ServerVersion; -import org.postgresql.core.TypeInfo; -import org.postgresql.core.Utils; -import org.postgresql.largeobject.LargeObject; -import org.postgresql.largeobject.LargeObjectManager; -import org.postgresql.util.ByteConverter; -import org.postgresql.util.GT; -import org.postgresql.util.HStoreConverter; -import org.postgresql.util.PGbytea; -import org.postgresql.util.PGobject; -import org.postgresql.util.PGtokenizer; -import org.postgresql.util.PSQLException; -import org.postgresql.util.PSQLState; - import java.io.ByteArrayInputStream; import java.io.CharArrayReader; import java.io.IOException; @@ -59,13 +36,11 @@ import java.sql.Statement; import java.sql.Time; import java.sql.Timestamp; import java.sql.Types; -//#if mvn.project.property.postgresql.jdbc.spec >= "JDBC4.2" import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.OffsetDateTime; import java.time.ZoneOffset; -//#endif import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; @@ -76,6 +51,28 @@ import java.util.Map; import java.util.StringTokenizer; import java.util.TimeZone; import java.util.UUID; +import org.postgresql.PGResultSetMetaData; +import org.postgresql.core.BaseConnection; +import org.postgresql.core.BaseStatement; +import org.postgresql.core.Encoding; +import org.postgresql.core.Field; +import org.postgresql.core.Oid; +import org.postgresql.core.Query; +import org.postgresql.core.ResultCursor; +import org.postgresql.core.ResultHandler; +import org.postgresql.core.ServerVersion; +import org.postgresql.core.TypeInfo; +import org.postgresql.core.Utils; +import org.postgresql.largeobject.LargeObject; +import org.postgresql.largeobject.LargeObjectManager; +import org.postgresql.util.ByteConverter; +import org.postgresql.util.GT; +import org.postgresql.util.HStoreConverter; +import org.postgresql.util.PGbytea; +import org.postgresql.util.PGobject; +import org.postgresql.util.PGtokenizer; +import org.postgresql.util.PSQLException; +import org.postgresql.util.PSQLState; public class PgResultSet implements ResultSet, org.postgresql.PGRefCursorResultSet { @@ -420,6 +417,13 @@ public class PgResultSet implements ResultSet, org.postgresql.PGRefCursorResultS return null; } + switch (getSQLType(i)) { + case Types.BINARY: + case Types.VARBINARY: + case Types.LONGVARBINARY: + return new PgByteaBlob(getBytes(i)); + } + return makeBlob(getLong(i)); } @@ -474,6 +478,14 @@ public class PgResultSet implements ResultSet, org.postgresql.PGRefCursorResultS return null; } + int type = getSQLType(i); + switch (type) { + case Types.CHAR: + case Types.VARCHAR: + case Types.LONGVARCHAR: + return new PgStringClob(getString(i)); + } + return makeClob(getLong(i)); } diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/PgStringClob.java b/pgjdbc/src/main/java/org/postgresql/jdbc/PgStringClob.java new file mode 100644 index 0000000..0382d77 --- /dev/null +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/PgStringClob.java @@ -0,0 +1,165 @@ +/*------------------------------------------------------------------------- +* +* Copyright (c) 2004-2015, PostgreSQL Global Development Group +* +* +*------------------------------------------------------------------------- + */ + +package org.postgresql.jdbc; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Reader; +import java.io.StringReader; +import java.io.UnsupportedEncodingException; +import java.io.Writer; +import java.sql.Clob; +import java.sql.SQLException; + +/** + * + * @author Thomas Kellerer + */ +public class PgStringClob + extends AbstractBasicLob + implements java.sql.Clob { + + private String content; + + public PgStringClob(String data) { + + this.content = data; + } + + @Override + public long length() + throws SQLException { + + return content.length(); + } + + @Override + public String getSubString(long pos, int length) + throws SQLException { + + assertPosition(pos); + + return content.substring((int)(pos - 1), (int)pos + length - 1); + } + + @Override + public Reader getCharacterStream() + throws SQLException { + + return new StringReader(content); + } + + @Override + public InputStream getAsciiStream() + throws SQLException { + + try { + return new ByteArrayInputStream(content.getBytes("UTF-8")); + } catch (UnsupportedEncodingException ex) { + // should not happen + throw new SQLException("UTF-8 not supported"); + } + } + + @Override + public long position(String searchstr, long start) + throws SQLException { + + assertPosition(start); + + return content.indexOf(searchstr, (int)start - 1) + 1; + } + + @Override + public long position(Clob searchstr, long start) + throws SQLException { + + assertPosition(start); + + String toSearch = searchstr.getSubString(1, (int)searchstr.length()); + return position(toSearch, start); + } + + @Override + public int setString(long pos, String str) + throws SQLException { + + assertPosition(pos); + + if (str == null) { + return 0; + } + + StringBuilder buffer = new StringBuilder(content.length()); + buffer.append(content.substring(0, (int)(pos - 1))); + buffer.append(str); + if (str.length() + (pos - 1) < content.length()) { + buffer.append(content.substring(str.length() + (int)(pos - 1))); + } + content = buffer.toString(); + return str.length(); + } + + @Override + public int setString(long pos, String str, int offset, int len) + throws SQLException { + + assertPosition(pos); + + if (str == null) { + return 0; + } + return setString(pos, str.substring(offset, offset + len)); + } + + @Override + public OutputStream setAsciiStream(long pos) + throws SQLException { + + throw org.postgresql.Driver.notImplemented(this.getClass(), "setAsciiStream(long)"); + } + + @Override + public Writer setCharacterStream(long pos) + throws SQLException { + + throw org.postgresql.Driver.notImplemented(this.getClass(), "setCharacterStream(long)"); + } + + @Override + public void truncate(long len) + throws SQLException { + + if (len > content.length()) { + // nothing to do + return; + } + content = content.substring(0, (int)len); + } + + @Override + public void free() + throws SQLException { + // nothing to do + } + + @Override + public Reader getCharacterStream(long pos, long length) + throws SQLException { + + return new StringReader(content.substring((int)(pos - 1), (int)length)); + } + + @Override + public String toString() { + return content; + } + +} diff --git a/pgjdbc/src/test/java/org/postgresql/jdbc/PgByteaBlobTest.java b/pgjdbc/src/test/java/org/postgresql/jdbc/PgByteaBlobTest.java new file mode 100644 index 0000000..8eb5897 --- /dev/null +++ b/pgjdbc/src/test/java/org/postgresql/jdbc/PgByteaBlobTest.java @@ -0,0 +1,114 @@ +/*------------------------------------------------------------------------- +* +* Copyright (c) 2004-2015, PostgreSQL Global Development Group +* +* +*------------------------------------------------------------------------- + */ + +package org.postgresql.jdbc; + +import static junit.framework.TestCase.assertEquals; +import static org.junit.Assert.assertArrayEquals; + +import org.junit.Test; + +/** + * + * @author Thomas Kellerer + */ +public class PgByteaBlobTest { + + public PgByteaBlobTest() { + } + + @Test + public void testLength() throws Exception { + byte[] data = new byte[]{1, 2, 3, 4}; + PgByteaBlob blob = new PgByteaBlob(data); + assertEquals(data.length, blob.length()); + } + + @Test + public void testGetBytes() throws Exception { + byte[] data = new byte[]{1, 2, 3, 4}; + PgByteaBlob blob = new PgByteaBlob(data); + assertArrayEquals(data, blob.getBytes(1, data.length)); + } + + @Test + public void testSetBytes1() throws Exception { + byte[] data = new byte[]{1, 2, 3, 4}; + PgByteaBlob blob = new PgByteaBlob(data); + blob.setBytes(2, new byte[]{0, 0}); + byte[] newData = blob.getBytes(); + assertEquals(4, newData.length); + assertEquals(1, newData[0]); + assertEquals(0, newData[1]); + assertEquals(0, newData[2]); + assertEquals(4, newData[3]); + + blob = new PgByteaBlob(data); + blob.setBytes(1, new byte[]{10, 11, 12, 13, 14, 15, 16}); + newData = blob.getBytes(); + assertEquals(7, newData.length); + for (int i = 0; i < newData.length; i++) { + assertEquals(10 + i, newData[i]); + } + } + + @Test + public void testSetBytes2() throws Exception { + byte[] data = new byte[]{1, 2, 3, 4}; + PgByteaBlob blob = new PgByteaBlob(data); + + byte[] data2 = new byte[]{1, 2, 3, 4, 5, 6, 7, 8}; + blob.setBytes(1, data2, 4, 1); + byte[] current = blob.getBytes(); + assertEquals(data.length, current.length); + assertEquals(5, current[0]); + + byte[] data3 = new byte[]{10, 11, 12, 13, 14, 15, 16}; + blob = new PgByteaBlob(new byte[]{1, 2, 3, 4}); + blob.setBytes(2, data3, 0, 7); + current = blob.getBytes(); + assertEquals(8, current.length); + assertEquals(1, current[0]); + for (int i = 1; i < current.length; i++) { + assertEquals(10 + i - 1, current[i]); + } + } + + @Test + public void testPosition1() + throws Exception { + + PgByteaBlob blob = new PgByteaBlob(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}); + long pos = blob.position(new byte[]{3, 4, 5}, 1); + assertEquals(3, pos); + + pos = blob.position(new byte[]{11, 4, 5}, 1); + assertEquals(-1, pos); + + pos = blob.position(new byte[]{1, 2, 3}, 3); + assertEquals(-1, pos); + + pos = blob.position(new byte[]{9, 10}, 1); + assertEquals(9, pos); + + pos = blob.position(new byte[]{9, 10}, 5); + assertEquals(9, pos); + + pos = blob.position(new byte[]{8, 9, 10}, 9); + assertEquals(-1, pos); + } + + @Test + public void testTruncate() throws Exception { + byte[] data = new byte[]{1, 2, 3, 4}; + PgByteaBlob blob = new PgByteaBlob(data); + blob.truncate(2); + assertEquals(2, blob.length()); + } + +} diff --git a/pgjdbc/src/test/java/org/postgresql/jdbc/PgStringClobTest.java b/pgjdbc/src/test/java/org/postgresql/jdbc/PgStringClobTest.java new file mode 100644 index 0000000..6372f15 --- /dev/null +++ b/pgjdbc/src/test/java/org/postgresql/jdbc/PgStringClobTest.java @@ -0,0 +1,91 @@ +/*------------------------------------------------------------------------- +* +* Copyright (c) 2004-2015, PostgreSQL Global Development Group +* +* +*------------------------------------------------------------------------- + */ + +package org.postgresql.jdbc; + +import static junit.framework.TestCase.assertEquals; + +import org.junit.Test; + +/** + * + * @author Thomas Kellerer + */ +public class PgStringClobTest { + + public PgStringClobTest() { + } + + @Test + public void testLength() + throws Exception { + String data = "Hello, Clob"; + PgStringClob clob = new PgStringClob(data); + assertEquals(data.length(), clob.length()); + } + + @Test + public void testGetSubString() + throws Exception { + String data = "Hello, Clob"; + PgStringClob clob = new PgStringClob(data); + String result = clob.getSubString(1, 5); + assertEquals("Hello", result); + } + + @Test + public void testPositionString() + throws Exception { + String data = "Hello, Clob"; + PgStringClob clob = new PgStringClob(data); + long result = clob.position(",", 1); + assertEquals(data.indexOf(',') + 1, result); + } + + @Test + public void testPositionClob() + throws Exception { + String data = "Hello, Clob"; + PgStringClob clob = new PgStringClob(data); + PgStringClob searchstr = new PgStringClob("Clob"); + long result = clob.position(searchstr, 1); + assertEquals(data.indexOf("Clob") + 1, result); + } + + @Test + public void testSetString1() + throws Exception { + String data = "Hello, Clob"; + PgStringClob clob = new PgStringClob(data); + clob.setString(8, "World"); + assertEquals("Hello, World", clob.toString()); + } + + @Test + public void testSetString2() + throws Exception { + } + + @Test + public void testTruncate() + throws Exception { + String data = "Hello, Clob"; + PgStringClob clob = new PgStringClob(data); + clob.truncate(5); + assertEquals(5, clob.length()); + assertEquals("Hello", clob.toString()); + } + + @Test + public void testToString() { + String data = "Hello, Clob"; + PgStringClob clob = new PgStringClob(data); + assertEquals(data, clob.toString()); + } + +} diff --git a/pgjdbc/src/test/java/org/postgresql/test/jdbc2/ResultSetTest.java b/pgjdbc/src/test/java/org/postgresql/test/jdbc2/ResultSetTest.java index 1bf861c..143dbb2 100644 --- a/pgjdbc/src/test/java/org/postgresql/test/jdbc2/ResultSetTest.java +++ b/pgjdbc/src/test/java/org/postgresql/test/jdbc2/ResultSetTest.java @@ -8,16 +8,16 @@ package org.postgresql.test.jdbc2; -import org.postgresql.test.TestUtil; -import org.postgresql.util.PGobject; - -import junit.framework.TestCase; - +import java.sql.Blob; +import java.sql.Clob; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Locale; +import junit.framework.TestCase; +import org.postgresql.test.TestUtil; +import org.postgresql.util.PGobject; /* * ResultSet tests. @@ -95,9 +95,10 @@ public class ResultSetTest extends TestCase { TestUtil.createTable(con, "testpgobject", "id integer NOT NULL, d date, PRIMARY KEY (id)"); stmt.execute("INSERT INTO testpgobject VALUES(1, '2010-11-3')"); - stmt.close(); - + TestUtil.createTable(con, "lob_test", "id integer NOT NULL, clob_data text, blob_data bytea, PRIMARY KEY (id)"); + stmt.executeUpdate("INSERT INTO lob_test VALUES(1, 'Hello, Clob', E'\\\\x01020304');"); + stmt.close(); } protected void tearDown() throws SQLException { @@ -112,6 +113,26 @@ public class ResultSetTest extends TestCase { TestUtil.closeDB(con); } + public void testGetLob() throws SQLException { + Statement stmt = con.createStatement(); + ResultSet rs = stmt.executeQuery( + "select id, clob_data, blob_data from lob_test"); + assertTrue(rs.next()); + int id = rs.getInt(1); + assertEquals(1, id); + Clob clob = rs.getClob(2); + assertNotNull(clob); + assertEquals("Hello, Clob", clob.getSubString(1, (int)clob.length())); + Blob blob = rs.getBlob(3); + assertNotNull(blob); + byte[] bytes = blob.getBytes(1, (int)blob.length()); + assertEquals(4, bytes.length); + assertEquals(1, bytes[0]); + assertEquals(2, bytes[1]); + assertEquals(3, bytes[2]); + assertEquals(4, bytes[3]); + } + public void testBackward() throws SQLException { Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
^ permalink raw reply [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2016-07-20 11:51 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:19   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:58     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
@ 2016-07-28 20:24       ` Thomas Kellerer <spam_eater@gmx.net>
  2016-07-28 20:46         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-28 20:47         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  1 sibling, 2 replies; 36+ messages in thread

From: Thomas Kellerer @ 2016-07-28 20:24 UTC (permalink / raw)
  To: pgsql-jdbc

Vladimir Sitnikov schrieb am 27.07.2016 um 21:58:
>
>     I think something similar is needed for PgPreparedStatement as well, but I did not find a way to check
>     the type of a column the way it's done in PgResultSet. It seems that ParameterList.getTypeOIDs()
>     would provide that information, but I don't know how to use that. If someone points me in the right
>     direction I can add that as well.
>
>
> I'm not yet ready to answer that.
>

It would be nice if someone else could point me in the right direction, because I think
that only a change to PreparedStatement would make that complete.






-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2016-07-20 11:51 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:19   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:58     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-28 20:24       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
@ 2016-07-28 20:46         ` Thomas Kellerer <spam_eater@gmx.net>
  1 sibling, 0 replies; 36+ messages in thread

From: Thomas Kellerer @ 2016-07-28 20:46 UTC (permalink / raw)
  To: pgsql-jdbc

Thomas Kellerer schrieb am 28.07.2016 um 22:24:
> Vladimir Sitnikov schrieb am 27.07.2016 um 21:58:
>>
>>     I think something similar is needed for PgPreparedStatement as well, but I did not find a way to check
>>     the type of a column the way it's done in PgResultSet. It seems that ParameterList.getTypeOIDs()
>>     would provide that information, but I don't know how to use that. If someone points me in the right
>>     direction I can add that as well.
>>
>>
>> I'm not yet ready to answer that.
>>
>
> It would be nice if someone else could point me in the right direction, because I think
> that only a change to PreparedStatement would make that complete.
>

I wonder if something like this would be correct to detect the column type in PgPreparedStatement:

   private boolean isBytea(int i) throws SQLException {
     TypeInfo info = connection.getTypeInfo();
     int columnOID = preparedParameters.getTypeOIDs()[i];
     String pgType = info.getPGType(columnOID);
     return "bytea".equals(pgType);
   }

   private boolean isVarchar(int i) throws SQLException {
     TypeInfo info = connection.getTypeInfo();
     int columnOID = preparedParameters.getTypeOIDs()[i];
     String pgType = info.getPGType(columnOID);
     return "text".equals(pgType) ||
            "varchar".equals(pgType) ||
            "character varying".equals(pgType) ||
            "char".equals(pgType);
   }

I chose to compare the Postgres Names rather than the java.sql.Type constants because it seems
that TypeInfoCache will send a SQL query to the backend (at least once) to get that mapping.

I am not sure if "character varying" will ever be needed. TypeInfoCache does not have that in its internal array
where oids are mapped to type names.


and then in the setClob() method:

     if (isVarchar(i)) {
       setString(i, x.getSubString(1, (int)x.length()));
       return;
     }

and for setBlob() the similar thing:

     if (isBytea(i)) {
       setBytes(i, x.getBytes(1, (int)x.length()));
       return;
     }





-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2016-07-20 11:51 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:19   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:58     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-28 20:24       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
@ 2016-07-28 20:47         ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-28 21:07           ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  1 sibling, 1 reply; 36+ messages in thread

From: Vladimir Sitnikov @ 2016-07-28 20:47 UTC (permalink / raw)
  To: Thomas Kellerer <spam_eater@gmx.net>; pgsql-jdbc

>It would be nice if someone else could point me in the right direction,
because I think
that only a change to PreparedStatement would make that complete.

Am I right your problem is "find a way to identify database type at
PreparedStatement#setClob time"?

I'm afraid, there's no solution for that.

Technically speaking, java types are used to parse the SQL properly.
Suppose there's a function process(int4) and function process(text). When
using prepareStatement("process(?)") at java side you can refer to both of
those and the exact overload depends on the setXXX method.
For instance, if you call setString, then process(text) variation will be
called.

Well, let's revert to our clob/text stuff.

I'm not quite sure we can easily figure out what is the proper data type
for the bind.

I do not like the idea "having additional round trip to the database just
to resolve desired bind types".
I do not like the idea of having a switch that binds setClob to text or lob
database types either.

Vladimir

^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2016-07-20 11:51 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:19   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:58     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-28 20:24       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-28 20:47         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
@ 2016-07-28 21:07           ` Thomas Kellerer <spam_eater@gmx.net>
  2016-07-28 22:20             ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  0 siblings, 1 reply; 36+ messages in thread

From: Thomas Kellerer @ 2016-07-28 21:07 UTC (permalink / raw)
  To: pgsql-jdbc

Vladimir Sitnikov schrieb am 28.07.2016 um 22:47:
>> It would be nice if someone else could point me in the right direction, because I think
>> that only a change to PreparedStatement would make that complete.
>
> Am I right your problem is "find a way to identify database type at PreparedStatement#setClob time"?
>
> I'm afraid, there's no solution for that.
>
> I'm not quite sure we can easily figure out what is the proper data type for the bind.
  
That's really a pity, because the (very unusual) handling of "large objects" makes the Clob/Blob handling quite
incompatiable with other JDBC implementations.


> I do not like the idea "having additional round trip to the database just to resolve desired bind types".

Me neither, that would be horrible.

> I do not like the idea of having a switch that binds setClob to text or lob database types either.

Well, in certain environments it would certainly make it easier to switch to Postgres.


Thomas





-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2016-07-20 11:51 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:19   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:58     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-28 20:24       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-28 20:47         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-28 21:07           ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
@ 2016-07-28 22:20             ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-29 06:07               ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  0 siblings, 1 reply; 36+ messages in thread

From: Vladimir Sitnikov @ 2016-07-28 22:20 UTC (permalink / raw)
  To: Thomas Kellerer <spam_eater@gmx.net>; pgsql-jdbc

>other JDBC implementations.

I've just looked into PgConnection.createClob, and it turns out the method
is not implemented.
This means no one ever used that to pass strings into large objects or
whatever thing.

Large object API works with bytes, not characters, so I think we can safely
assume that PgPreparedStatement.setClob results into string datatype (that
is it should be just redirected to setString).

This (plus the patch that enables to getClob for textual results) should
solve the problem for the majority of pgjdbc users.

Thomas is that enough so you can give it a try?


That's really a pity, because the (very unusual) handling of "large
> objects" makes the Clob/Blob handling quite
> incompatiable with other JDBC implementations.
>

The problem with Blob remains (I'm not sure if you have one): postgresql
cannot automatically create a large object when it receives "bytea" bind.

For instance, we have pretty much similar problem with timestamp kind of
types: setTimestamp() does not say much if "with time zone" or "without
time zone" type should be used, so pgjdbc just sends a sting with
"oid.UNKNOWN" in a hope that backend will figure out the proper timestamp
type (luckily it can ignore time zone part when without time zone is
required).

The same "unknown" approach does not work here since "large objects" are
stored aside and a colum contains just a "oid" (64bit id).

That adds yet another case "bytea vs large object" to
https://github.com/pgjdbc/pgjdbc/blob/master/backend_protocol_v4_wanted_features.md#binary-transfer-...


Vladimir

^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
  2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
  2016-07-20 11:51 ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:19   ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-27 19:58     ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-28 20:24       ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-28 20:47         ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
  2016-07-28 21:07           ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Thomas Kellerer <spam_eater@gmx.net>
  2016-07-28 22:20             ` Re: ResultSet.getClob() causing problems when used with JPA's @Lob Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
@ 2016-07-29 06:07               ` Thomas Kellerer <spam_eater@gmx.net>
  0 siblings, 0 replies; 36+ messages in thread

From: Thomas Kellerer @ 2016-07-29 06:07 UTC (permalink / raw)
  To: pgsql-jdbc

Vladimir Sitnikov schrieb am 29.07.2016 um 00:20:
>>other JDBC implementations.
> 
> I've just looked into PgConnection.createClob, and it turns out the method is not implemented.
> This means no one ever used that to pass strings into large objects or whatever thing.

I noticed that as well. I wonder if we could use the PgStringClob and PgStringBlob I included with my patch for that purpose? 

I think the missing methods in those two classes shouldn't be that hard to implement.


> Large object API works with bytes, not characters, so I think we can
> safely assume that PgPreparedStatement.setClob results into string
> datatype (that is it should be just redirected to setString).
> 
> This (plus the patch that enables to getClob for textual results) should solve the problem for the majority of pgjdbc users. 
> 
> Thomas is that enough so you can give it a try?

Redirecting setClob() to setString() unconditionally would help us in the current migration, yes. 

I can submit a patch for that, sounds easy enough.

>     That's really a pity, because the (very unusual) handling of "large objects" makes the Clob/Blob handling quite
>     incompatiable with other JDBC implementations.
> 
> The problem with Blob remains (I'm not sure if you have one): 
> postgresql cannot automatically create a large object when it receives "bytea" bind.
> 
> The same "unknown" approach does not work here since "large objects" are stored aside and a colum contains just a "oid" (64bit id).
> 
> That adds yet another case "bytea vs large object" to
> https://github.com/pgjdbc/pgjdbc/blob/master/backend_protocol_v4_wanted_features.md#binary-transfer-...

I still think that having a connection property that switches between large objects and bytea for BLOBs makes sense. 

Thomas







-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 36+ messages in thread

* Re: ResultSet.getClob() causing problems when used with JPA's @Lob
@ 2011-02-08 14:32 Andreas Joseph Krogh <andreak@officenet.no>
  0 siblings, 0 replies; 36+ messages in thread

From: Andreas Joseph Krogh @ 2011-02-08 14:32 UTC (permalink / raw)
  To: pgsql-jdbc

På tirsdag 08. februar 2011 kl 14:25:18 skrev "Oliver Jowett" <oliver@opencloud.com>:
> Andreas Joseph Krogh wrote:
> > På tirsdag 08. februar 2011 kl 13:31:21 skrev du:
> >> Andreas Joseph Krogh wrote:
> >>
> >>> ...but the StringClobType is deprecated.
> >> The obvious question here is "why?"
> > 
> > I totally agree that Hibernate is not behaving as it should when encountering a String property annotated with @Lob. I just wanted to shed some light on what rational PG has for implementing setClob() as it is and not just as a wrapper for setString.
> 
> My point about the "why?" is that there was presumably some reason why 
> it is deprecated and investigating what that reason is may be enlightening.
> 
> > If I get it right the justification for it being as it is is not to break old apps, in case they use OID for large character types of data and not varchar or text. I would be very surprised if any such applications still exist...
> 
> Well, it's also arguably a more natural mapping of the CLOB type (go and 
> read the javadoc at 
> http://download.oracle.com/javase/6/docs/api/java/sql/Clob.html; for 
> "logical pointer" read "OID" and you essentially have the postgres 
> implementation right there)
> 
> It's been this way for ages with no problems, it's a reasonable 
> spec-compliant implementation, so you need a good argument for changing 
> it now. Your argument doesn't seem to go beyond "it doesn't do this 
> non-standard thing I want it to do" which is not very convincing to me.

To me the whole CLOB type seems to be superfluous and only exists to satisfy RDBMS-vendors with broken(...) implementations of varchar/text-types. CLOBs really shouldn't be necessary these days. PG can and does better by allowing arbitrary length of text stored in varchar/text-columns. Feel free to disagree.

> If you do think it's useful to change then you need to discuss it with 
> Kris since he's basically looking after the driver solo these days (I 
> unfortunately have no time to spend on the driver any more, and even 
> this list discussion has eaten up all my JDBC time for about the next 
> month). I anticipate he'll be worried about breaking compatibility so 
> you'll need a good argument there.

I don't feel I'm in the position to push a new implementation of CLOB in the PG-JDBC-driver forward and don't want to waste anyones time any more on this issue.

But - having this discussion has shed some light on the issue and might be useful for archiving purpose if the CLOB issue some day resurrects.

--
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 |                                             |
------------------------+---------------------------------------------+



^ permalink  raw  reply  [nested|flat] 36+ messages in thread


end of thread, other threads:[~2016-07-29 06:07 UTC | newest]

Thread overview: 36+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-02-06 23:01 ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>
2011-02-07 08:11 ` Radosław Smogura <rsmogura@softperience.eu>
2011-02-07 20:50   ` Andreas Joseph Krogh <andreak@officenet.no>
2011-02-07 21:38     ` Radosław Smogura <rsmogura@softperience.eu>
2011-02-07 23:25       ` Andreas Joseph Krogh <andreak@officenet.no>
2011-02-08 00:53         ` Oliver Jowett <oliver@opencloud.com>
2011-02-08 09:02           ` Andreas Joseph Krogh <andreak@officenet.no>
2011-02-08 10:35             ` Oliver Jowett <oliver@opencloud.com>
2011-02-08 11:34               ` Andreas Joseph Krogh <andreak@officenet.no>
2011-02-08 12:30                 ` Oliver Jowett <oliver@opencloud.com>
2011-02-08 12:31                 ` Oliver Jowett <oliver@opencloud.com>
2011-02-08 15:18                 ` Radosław Smogura <rsmogura@softperience.eu>
2011-02-09 03:23                 ` Lew <noone@lewscanon.com>
2011-02-10 07:39                   ` Andreas Joseph Krogh <andreak@officenet.no>
2011-02-09 00:20     ` Kris Jurka <books@ejurka.com>
2011-02-09 08:04       ` Andreas Joseph Krogh <andreak@officenet.no>
2011-02-09 09:40         ` Oliver Jowett <oliver@opencloud.com>
2011-02-10 18:24         ` Radosław Smogura <rsmogura@softperience.eu>
2016-07-20 11:51 ` Thomas Kellerer <spam_eater@gmx.net>
2016-07-20 12:37   ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
2016-07-20 13:40     ` Thomas Kellerer <spam_eater@gmx.net>
2016-07-20 13:52       ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
2016-07-20 14:55         ` Thomas Kellerer <spam_eater@gmx.net>
2016-07-20 15:47           ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
2016-07-27 19:19   ` Thomas Kellerer <spam_eater@gmx.net>
2016-07-27 19:58     ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
2016-07-28 05:37       ` Thomas Kellerer <spam_eater@gmx.net>
2016-07-28 13:57         ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
2016-07-28 20:23           ` Thomas Kellerer <spam_eater@gmx.net>
2016-07-28 20:24       ` Thomas Kellerer <spam_eater@gmx.net>
2016-07-28 20:46         ` Thomas Kellerer <spam_eater@gmx.net>
2016-07-28 20:47         ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
2016-07-28 21:07           ` Thomas Kellerer <spam_eater@gmx.net>
2016-07-28 22:20             ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
2016-07-29 06:07               ` Thomas Kellerer <spam_eater@gmx.net>
2011-02-08 14:32 Re: ResultSet.getClob() causing problems when used with JPA's @Lob Andreas Joseph Krogh <andreak@officenet.no>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox