Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 337467

Summary: Incorrect handling of PostgreSQL's BLOB
Product: z_Archived Reporter: Michal Piotrowski <mpiotrowski>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P2 CC: aaron.lisman, igor.paunov, lista, martin.grebac, nenad, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard: postgresql
Attachments:
Description Flags
Code for recognizing blob's in PostgreSQL none

Description Michal Piotrowski CLA 2011-02-17 12:01:41 EST
Build Identifier: 2.1.2.v20101206-r8635

There are 2 binary types in PotgreSQL: bytea and Blob. bytea is correctly supported in EclipseLink JPA, but Blob is not correctly implemented.

Blobs in PostgreSQL are linked into table columns as blob's OID number, so column type is OID. PostgreSQL driver returns for this column:
TYPE_NAME="oid"
DATA_TYPE=java.sql.Types.BIGINT
But it is possible to obtain Blob using ResultSet.getBlob() method.

EclipseLink thinks that blob column should be a java.lang.Long and can't read the blob. The result is that correctly annotated by @Lob PostgreSQL's blob columns can't be read.

I think that EclipseLink should read oid columns as Blob if they are annotated as @Lob.

I would like to add, that when I tested Hibernate JPA some time ago, Hibernate expected serializable fields annotated with @Lob to be oids in PostgreSQL, and serializable fields without @Lob annotation to be bytea (java.sql.Types.BINARY). I think that this approach to PostgreSQL binary types should be treated as the correct one.

Reproducible: Always

Steps to Reproduce:
1. Create table with BLOB's in PostgreSQL: "create table test (id serial primary key, data oid);"
2. Import some blob using psql: "\lo_import a_file_name"
3. Insert into table blob oid returned by \lo_import, eg: "insert into test values (1, 36253);"
4. Create @Entity with @Lob field and try to read the database row.
Comment 1 Michal Piotrowski CLA 2011-02-17 12:23:59 EST
Created attachment 189206 [details]
Code for recognizing blob's in PostgreSQL

This is a very simple patch which correctly recognizes BLOBs in PostgreSQL.

I couldn't correctly test it in JavaSE, because EclipseLink works in JDBC autoCommit mode, and BLOBs in PostgreSQL can't be read in autoCommit mode. :(

I have tried:
entityManager.getTransaction().begin(); 
before executing:
entityManager.find()
but drivers autoCommit mode wasn't disabled!

I'm afraid that I don't know EclipseLink code well enough to propose fully working patch.
Comment 2 Tom Ware CLA 2011-02-24 08:41:25 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:31:45 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink