简而言之
如何使用longblob
s.t将pgloader
从MySQL迁移到Postgres。如果列被注释为@Lob
和@Basic(fetch= FetchType.LAZY)
,Hibernate很高兴?
完整故事
因此,我正在将MySQL数据库迁移(或至少尝试)到postgres。我现在正尝试正确移动此表:
我当前的pgloader脚本非常简单:
LOAD DATABASE
FROM mysql://foo:bar@localhost:3306/foobar
INTO postgresql://foo:bar@localhost:5432/foobar
CAST
type int to integer drop typemod,type bigint with extra auto_increment to bigserial drop typemod,type bigint to bigint drop typemod
ALTER TABLE NAMES MATCHING 'User' RENAME TO 'users'
ALTER TABLE NAMES MATCHING ~/./ SET SCHEMA 'public'
;
这足以加载数据并使外键正常工作。
postgres表如下:
File
是Java实体,其内容带有注释@Lob
:
@Entity
@Inheritance(strategy= InheritanceType.JOINED)
public class File extends BaseEntity {
@NotNull
private String name;
@Column
@Size(max = 4096)
private String description;
@NotNull
private String mimeType;
@Lob
@Basic(fetch= FetchType.LAZY)
private transient byte[] content;
...
}
这就是为什么应用程序无法连接到错误的迁移数据库的原因:
Schema-validation: wrong column type encountered in column [content] in table [File];
found [bytea (Types#BINARY)],but expecting [oid (Types#BLOB)]
如何使此迁移正常工作?
我确实尝试过设置
spring.jpa.properties.hibernate.jdbc.use_streams_for_binary=false
如proper hibernate annotation for byte[]中的建议,但这没有任何作用。