Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 337467 - Incorrect handling of PostgreSQL's BLOB
Summary: Incorrect handling of PostgreSQL's BLOB
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P2 normal with 6 votes (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard: postgresql
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-17 12:01 EST by Michal Piotrowski CLA
Modified: 2022-06-09 10:31 EDT (History)
6 users (show)

See Also:


Attachments
Code for recognizing blob's in PostgreSQL (802 bytes, text/plain)
2011-02-17 12:23 EST, Michal Piotrowski CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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