varchar(255), primary key (id))
create table centert (bid integer, aid integer not null, primary key (aid))
alter table centert add index FK27A6BEBFFCA6C7EA (bid), add constraint FK27A6BEBFFCA6C7EA foreign key (bid) references B (id)
alter table centert add index FK27A6BEBFFCA6C428 (aid), add constraint FK27A6BEBFFCA6C428 foreign key (aid) references A (id)
manytoone
和onetoone很相似
特殊情况:果不写:mappedBy这会产生中间表:
Java代码
create table A (id integer not null auto_increment, aname varchar(255), i_id integer, primary key (id))
create table B (id integer not null auto_increment, bname varchar(255), primary key (id))
create table B_A (B_id integer not null, a_id integer not null, unique (a_id))
alter table A add index FK41FCD6779E (i_id), add constraint FK41FCD6779E foreign key (i_id) references B (id)
alter table B_A add index FK10384FCD34905 (B_id), add constraint FK10384FCD34905 foreign key (B_id) references B (id)
alter table B_A add index FK10384FCD2D4A5 (a_id), add constraint FK10384FCD2D4A5 foreign key (a_id) references A (id)
如
targetEntity属性可以关联接口
例如接口代码
Java代码
public interface I {
}
class B implments I
关联方:
Java代码
private I i;
@ManyToOne(targetEntity=B.class)
public I getI() {
return i;
}
最终sql:
Java代码
create table A (id integer not null auto_increment, aname varchar(255), i_id integer, primary key (id))
create table B (id integer not null auto_increment, bname varchar(255), primary key (id))
alter table A add index FK41FCD6779E (i_id), add constraint FK41FCD6779E foreign key (i_id) references B (id)
|