更新:我从问题中消除了休眠。我完全重新编写了对问题的描述,以尽可能地简化它。
我有master带noop触发器的detail表和带master和detail表之间的两个关系的表:
create table detail (
id bigint not null,
code varchar(255) not null,
primary key (id)
);
create table master (
id bigint not null,
name varchar(255),
detail_id bigint, -- "preferred" detail is one-to-one relation
primary key (id),
unique (detail_id),
foreign key (detail_id) references detail(id)
);
create table detail_candidate ( -- "candidate" details = many-to-many relation modeled as join table
master_id bigint not null,
detail_id bigint not null,
primary key (master_id, …Run Code Online (Sandbox Code Playgroud)