Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java PostgreSQL中的字节[]数据_Java_Postgresql_Hibernate_Jpa - Fatal编程技术网

Java PostgreSQL中的字节[]数据

Java PostgreSQL中的字节[]数据,java,postgresql,hibernate,jpa,Java,Postgresql,Hibernate,Jpa,我有一个spring应用程序,它使用MySQL作为数据库 我想把应用从MySQL迁移到Postgres,看来我不能声明byte[]数组: 我有以下专栏: @Type(type="org.hibernate.type.BinaryType") private byte[] data. 我得到这个错误: Caused by: org.postgresql.util.PSQLException: ERROR: type "tinyblob" does not exist 有没有办法在Postgre

我有一个spring应用程序,它使用MySQL作为数据库

我想把应用从MySQL迁移到Postgres,看来我不能声明byte[]数组:

我有以下专栏:

@Type(type="org.hibernate.type.BinaryType")
private byte[] data.
我得到这个错误:

Caused by: org.postgresql.util.PSQLException: ERROR: type "tinyblob" does not exist

有没有办法在PostgreSQL中实现这一点?

在您的PostgreSQL数据库表中,将
数据
列数据类型设置为
bytea
而不是
bytea[]
在你的POJO课程中:

@Column(name=“你的列的名称”)
专用字节[]数据

省略
@Type(Type=“org.hibernate.Type.BinaryType”)
注释


这应该可以正常工作。

您需要在JPA提供程序中指定PostgreSQL方言,在连接到PostgreSQL时,您当前似乎正在使用MySQL方言。您可能需要指定正在使用的JPA提供程序(根据其外观休眠)。您还需要确保您的模糊层(=ORM)使用
bytea
作为该列的数据类型。除了@markrotVeel所说的,不需要使用
@type
注释。在实体类定义中,如果我只声明类型,则我有一个来自post的错误。请检查此链接: