Problem loading after hibernation

I use Hibernate 4.0 to store jpegs in postgres 9.1.4 (jdbc is postgresql-9.1-901.jdbc4.jar) bytea column (byte [] is a sleep object, without an additional def type).

The hibernation storage process works fine because I can use the database tools to unload the bytea column and get jpeg. This is basically:

In 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 begins with me returning through sleep mode. The data seems to be altered or corrupted somehow.

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

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

Sleeping getter

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

Appreciate if anyone can help, thanks!

+2
1

bytea_output = 'escape' postgresql.conf

ALTER DATABASE dbname SET bytea_output TO 'escape';

+3

Source: https://habr.com/ru/post/1629561/


All Articles