Reputation: 1253
I want to store image into database using hibernate and Java. I am using postgres database
I tried bytea
data type to store image and 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 error at time of mapping.
please give me any reference to do this.
Upvotes: 4
Views: 15461
Reputation: 324475
If you are using Hibernate via JPA2, you may need the @Lob
annotation, though I'm not sure if that's for oid
or bytea
fields. See:
proper hibernate annotation for byte[]
There's also a Hibernate dev blog post that's quite informative.
If you're using Hibernate via XML mappings or its own annotations dialect, please show your exact code and error message(s).
See also the answers here.
Upvotes: 5