When declaring a mapping as follows:
{code:java}
@Entity @Table(name = "EMPLOYEE") public class Employee { @Id @GeneratedValue private Long id;
@ManyToMany @JoinTable(name = "EMPLOYEE_PROJECT", joinColumns = @JoinColumn(name = "EMPLOYEE_ID", foreignKey = @ForeignKey(name = "FK_EMPLOYEE")), inverseJoinColumns = @JoinColumn(name = "PROJECT_ID", foreignKey = @ForeignKey(name = "FK_PROJECT"))) private Set<Project> projects;
} {code}
{code:java} @Entity @Table(name = "PROJECT") public class Project { @Id @GeneratedValue private Long id;
@ManyToMany(mappedBy="projects") private Set<Employee> employees;
} {code}
the generated schema is
{code:java} create table EMPLOYEE (id bigint not null, primary key (id))
create table EMPLOYEE_PROJECT (EMPLOYEE_ID bigint not null, PROJECT_ID bigint not null, primary key (EMPLOYEE_ID, PROJECT_ID))
create table PROJECT (id bigint not null, primary key (id))
alter table EMPLOYEE_PROJECT add constraint FKc9v0x49gwfm2m9wal4r6fujq6 foreign key (PROJECT_ID) references PROJECT
alter table EMPLOYEE_PROJECT add constraint FKa9av8l4b215ry58ocy8h646ge foreign key (EMPLOYEE_ID) references EMPLOYEE {code}
|
|