2

I am using Hibernate 4.0 to store jpegs into postgres 9.1.4 (jdbc is postgresql-9.1-901.jdbc4.jar) bytea column(byte[] is the hibernate entity, without extra type def).

The hibernate storing process works fine because I can use Database tools to dump the bytea column and still get the jpegs. It is basically:

In the managedBean

byte [] bytes;
bytes = IOUtils.toByteArray(file.getInputstream());
entity.setImage(bytes);

At this point, the bytes look like [-1, -40, -1, -32, 0, 16, 74, 70, ...]

However, the problem starts with I am retrieving via hibernate. The data seems modified or corrupted somehow.

byte [] bytes;
bytes = entity.getImage();

At this point, the bytes become [-26, 100, 56, 102, 102, 101, 48, 48,...]

The hibernate getter is

@Column(name = "image")
public byte[] getImage() {
    return image;
}

Appreciate if anyone can assist, thanks!

2

1 Answer 1

3

change bytea_output='escape' in postgresql.conf

or run this

ALTER DATABASE dbname SET bytea_output TO 'escape';

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.