使用带弹簧

时间:2018-04-29 09:43:18

标签: java sql spring postgresql

我正在尝试在加载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[]),但没有运气。

感谢。

1 个答案:

答案 0 :(得分:1)

使用pg_read_binary_file读取二进制文件。