How to save image in postgres database using sleep mode

I want to save an image to a database using hibernate and Java. I am using postgres database

I tried the bytea data bytea to store the image and the byte[] data type in hibernate pojo.

I used the following code,

 CREATE TABLE photo ( "photo_name" bytea ) WITH (OIDS=FALSE); ALTER TABLE photo OWNER TO postgres; 

Hibernate pojo

 public class PhotoEntity { byte[] name; public byte[] getName() { return name; } public void setName(byte[] name) { this.name = name; } 

}

but it gives an error while displaying.
please give me a link to this.

+4
source share
1 answer

If you use Hibernate through JPA2, you may need the @Lob annotation, although I'm not sure if this is for oid or bytea . Cm:

correct hibernation annotation for byte []

There is also a Hibernate dev blog post , which is pretty informative.

If you use Hibernate through XML mappings or your own annotation dialect, please show your exact codes and error messages.

See. Also answers here .

+5
source

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


All Articles