我正在尝试将 Spring Data JDBC 用于我的 PostgreSQL 数据库。我定义了以下bean
@Data
class Report {
@Id
private Long id;
private String name;
private Set<Dimension> dimensions;
}
@Data
class Dimension {
private String name;
private Long[] filterIds;
}
和相应的 DDL
CREATE TABLE report (
id bigserial PRIMARY KEY,
name text NOT NULL
);
CREATE TABLE dimension (
id bigserial PRIMARY KEY ,
report bigint,
name text,
filter_ids bigint[],
FOREIGN KEY (report) REFERENCES report(id) ON DELETE CASCADE ON UPDATE CASCADE
);
然后我尝试插入报告
final Dimension dimension = new Dimension();
dimension.setName("xyz");
dimension.setFilterIds(new Long[]{ 1L, 2L, 3L });
final Report report = new Report();
report.setName("xyz");
report.setDimensions(Collections.singleton(dimension));
repository.save(report);
whererepository
只是一个CrudRepository<Report, Long>
.
这给了我以下错误
org.postgresql.util.PSQLException: ERROR: column "filter_ids" is of type bigint[] but expression is of type bigint
Hinweis: You will need to rewrite or cast the expression.
Position: 116
我可以以某种方式告诉 Spring Data JDBC 如何映射数组类型吗?