Quote:
I cannot give you example for MySQL, but in PostgreSQL is something like:
Code:
@Lob
Blob bytes;
or
Code:
@Lob
@Column(columnDefinition="bytea")
byte[] bytes;
[/code]
I tried this but got a weird error message. It seems the generated insert statement tried to insert an integer. Here's a snippet of the log:
Code:
17:34:26,373 ERROR JDBCExceptionReporter:72 - Batch entry 0 insert into Photo (dogID, image, id) values (2, 16891, 3) was aborted. Call getNextException to see the cause.
17:34:26,373 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: 42804
17:34:26,373 ERROR JDBCExceptionReporter:72 - ERROR: column "image" is of type bytea but expression is of type integer
17:34:26,383 ERROR AbstractFlushingEventListener:301 - Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
Here's the column mapping in the Photo class:
Code:
@Lob
@Column(columnDefinition="bytea")
private byte[] image;
public byte[] getImage(){return image;}
public void setImage(byte[] image){
this.image = image;
}
Have anyone encoutered this before? Or perhaps successfully stored an image into a PostgreSQL database?
Thanks,
Dany.