Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.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
Hibernate,Postgresql:Column";x";是oid类型,但表达式是byte类型_Hibernate_Postgresql_Annotations_Bytearray_Oid - Fatal编程技术网

Hibernate,Postgresql:Column";x";是oid类型,但表达式是byte类型

Hibernate,Postgresql:Column";x";是oid类型,但表达式是byte类型,hibernate,postgresql,annotations,bytearray,oid,Hibernate,Postgresql,Annotations,Bytearray,Oid,在不同的数据库之间切换时,关于包含大对象(BLOB)的hibernate映射,我有一个奇怪的问题 @Lob private byte[] binaryData; 上面的字段在MySQL和Oracle中创建字节数组字段,但在PostreSQL中创建oid类型的字段 现在,当我尝试访问此字段时,它在其他数据库中工作正常,但在PostgreSQL中失败,出现以下错误 Column "binaryData" is of type oid but expression is of type bytea.

在不同的数据库之间切换时,关于包含大对象(BLOB)的hibernate映射,我有一个奇怪的问题

@Lob
private byte[] binaryData;
上面的字段在MySQL和Oracle中创建字节数组字段,但在PostreSQL中创建oid类型的字段

现在,当我尝试访问此字段时,它在其他数据库中工作正常,但在PostgreSQL中失败,出现以下错误

Column "binaryData" is of type oid but expression is of type bytea.
因此,我试图简单地删除“@Lob”注释,这将解决PostgreSQL的问题,但是在没有此注释的MySQL中,hibernate创建了一个类型为“tinyblob”的字段,在我们的大多数情况下,该字段太小了。而且,由于我们希望在多个环境中使用此项目,因此切换两个不同的映射很烦人

是否有任何注释强制postgreSQL对带有@Lob注释的字段使用bytea而不是oid?或者,是否有可能省略@Lob并添加其他内容,以迫使MySQL像使用@Lob那样为其分配更大的数据类型

我甚至可以想象有这样的解决方案

if (field is of type oid)
  store it as oid
else if (field is of type bytea)
  store it as bytea
else
  // not storable
和getter一样,如果有一种方法可以做到这一点的话

编辑:

以下声明正在起作用。它将列分配为oid,但是使用它的hibernate知道如何从这样的字段中存储和检索数据

@Lob
@Type(type="org.hibernate.type.PrimitiveByteArrayBlobType")
private byte[] binaryFile;

此字段映射在
org.hibernate.dialogue.PostgreSqlDialogue
中定义,可以通过将其子类化并将应用程序配置为在使用postgres运行时使用修改过的方言来更改

子类中的相关咒语可能是

    registerColumnType( Types.BLOB, "bytea" );

在调用
super()

之后,在构造函数中,这可能意味着有一次“将postgres jdbc版本还原到9.3-1101.jdbc4”


org.postgresql
postgresql
9.4-1200-jdbc41

工作也很顺利。比失败的更新…

自Hibernate 3.6以来,该类已被弃用。现在,对于最新的Hibernate,我们需要使用
@Type(Type=“org.Hibernate.Type.MaterializedBlobType”)
。有关更多信息,请查看和。

嗨,唐!谢谢你的回答。我尝试了一下,效果很好,但同时我发现了一个简单的解决方案,并将其添加到问题中
  <dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>9.4-1200-jdbc41</version>
  </dependency>