我正在尝试在加载 spring
时使用 import.sql
文件将图像文件添加到数据库中。我目前正在使用 postgresql
。
我的字节数组在我的项目
类中:
@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[])
但没有成功。
谢谢。
最佳答案
使用pg_read_binary_file
读取二进制文件。
关于java - 使用带有 spring 的 import.sql 将图像存储为 byte[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50085255/