我正在尝试在加载import.sql
时使用spring
文件将图像文件添加到数据库中。我目前正在使用postgresql
。
我的字节数组在我的project
类中:
@Lob
private byte[] bytes;
我试图通过pg_read_file
导入文件,如下所示:
-- Insert into Project
insert into project (title, colour, description, project_user_id, bytes) values ('Test', '#F6D2B4', 'a short description of some project, making sure its over 50 characters', 1, pg_read_file('classpath:static/images/pon9s2N.jpg'))
但是在运行spring时出现以下错误:
2018-04-29 10:33:43.812 ERROR 540 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000388: Unsuccessful: insert into project (title, colour, description, project_user_id, bytes) values ('Test', '#F6D2B4', 'a short description of some project, making sure its over 50 characters', 1, pg_read_file('classpath:static/images/pon9s2N.jpg'))
2018-04-29 10:33:43.813 ERROR 540 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : ERROR: column "bytes" is of type oid but expression is of type text
Hint: You will need to rewrite or cast the expression.
Position: 179
我尝试使用CAST(pg_read... AS byte[])
,但没有运气。
感谢。