Java pgloader-如何将longblob作为oid导入?
简而言之 如何使用Java pgloader-如何将longblob作为oid导入?,java,postgresql,hibernate,jpa,pgloader,Java,Postgresql,Hibernate,Jpa,Pgloader,简而言之 如何使用pgloaders.t.将longblob从MySQL迁移到Postgres。如果列被注释为@Lob和@Basic(fetch=FetchType.LAZY),Hibernate会很高兴的 完整故事 所以我正在迁移(或者至少尝试)一个MySQL数据库到postgres。我现在正试图正确地移动这张桌子: 我当前的pgloader脚本相当简单: LOAD DATABASE FROM mysql://foo:bar@localhost:3306/foobar
pgloader
s.t.将longblob
从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表如下所示:
然而,文件
是一个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
正如中所建议的,但这没有起任何作用。嗯。。。我想我可以在事实发生后创建blob,正如 这意味着迁移脚本将获得扩展:
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'
AFTER LOAD DO
$$
ALTER TABLE file RENAME COLUMN content TO content_bytes;
$$,
$$
ALTER TABLE file ADD COLUMN content OID;
$$,
$$
UPDATE file SET
content = lo_from_bytea(0, content_bytes::bytea),
content_bytes = NULL
;
$$,
$$
ALTER TABLE file DROP COLUMN content_bytes
$$
;
嗯。。。我想我可以在事实发生后创建blob,正如 这意味着迁移脚本将获得扩展:
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'
AFTER LOAD DO
$$
ALTER TABLE file RENAME COLUMN content TO content_bytes;
$$,
$$
ALTER TABLE file ADD COLUMN content OID;
$$,
$$
UPDATE file SET
content = lo_from_bytea(0, content_bytes::bytea),
content_bytes = NULL
;
$$,
$$
ALTER TABLE file DROP COLUMN content_bytes
$$
;