Hibernate, Postgresql: Column “x” is of type oid but expression is of type byte

后端 未结 3 1994
南笙
南笙 2020-12-10 03:47

I have a strange problem regarding the hibernate mapping containing large objects (BLOB), when switching between different databases.

@Lob
private byte[] bin         


        
相关标签:
3条回答
  • 2020-12-10 04:19

    This field mapping is defined in org.hibernate.dialect.PostgreSQLDialect and can be changed by subclassing this and configuring your app to use the modified dialect when running with postgres.

    The relevant incantation in the subclass is probably to put

        registerColumnType( Types.BLOB, "bytea" );
    

    in your constructor after a call to super().

    0 讨论(0)
  • 2020-12-10 04:24

    The class is deprecated since Hibernate 3.6. Now with latest Hibernate we need to use @Type(type="org.hibernate.type.MaterializedBlobType") instead. Please check https://docs.jboss.org/hibernate/core/3.6/javadocs/deprecated-list.html and https://docs.jboss.org/hibernate/core/3.6/javadocs/org/hibernate/type/MaterializedBlobType.html for more information.

    0 讨论(0)
  • 2020-12-10 04:31

    For me this may have meant once "revert your postgres jdbc version back down to 9.3-1101.jdbc4"

      <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.4-1200-jdbc41</version>
      </dependency>
    

    worked as well. Newer than that failed...

    0 讨论(0)
提交回复
热议问题