【发布时间】:2018-05-28 11:29:26
【问题描述】:
我有具有多个模式的 PostgreSQL 数据库,并且我正在使用 Apache Cayenne 生成 Java 类。问题是 cayenne 在不同模式的表上跳过了外键。示例:
引用schema_a.my_user的表schema_b.booking:
create table schema_b.booking
(
id bigserial not null constraint booking_pkey primary key,
address_id integer not null constraint cde_fk references schema_b.address
...,
created_by integer not null constraint abc_fk references schema_a.my_user
);
生成的 Java 类如下所示:
class Booking {
private Long id;
private Address addressId; //this is OK
private Integer createdBy; //NOT OK (Integer instead of MyUser)
}
控制台日志为不同架构中的每个 FK 显示此条目:
[INFO] Skip relation: 'null.schema_a.my_user.id <- null.schema_b.booking.created_by # 1' because it related to objects from other catalog/schema
[INFO] relation primary key: 'null.schema_a'
[INFO] primary key entity: 'null.schema_a'
[INFO] relation foreign key: 'null.schema_b'
[INFO] foreign key entity: 'null.schema_b'
问题是Booking#createdBy 不是MyUser。
我搜索了 SO 和官方文档,但没有成功。有什么办法可以做到这一点?我知道另一种选择是将所有表移动到单个模式中,但这对我们的项目来说几乎是不可行的。
【问题讨论】:
标签: java postgresql apache-cayenne