我有2张桌子。第二个表包含两个FK到第一个(意思是用户可以拥有其他用户的团队)。
CREATE TABLE "user" (
usr_id INTEGER PRIMARY KEY,
usr_login VARCHAR NOT NULL UNIQUE,
);
CREATE TABLE user_team (
utm_id INTEGER PRIMARY KEY,
usr_id INTEGER NOT NULL UNIQUE,
manager_id INTEGER NOT NULL,
CONSTRAINT utm_usr_fk FOREIGN KEY (usr_id)
REFERENCES "user" (usr_id) ON DELETE CASCADE,
CONSTRAINT utm_manager_fk FOREIGN KEY (manager_id)
REFERENCES "user" (usr_id) ON DELETE CASCADE
);
我可以在User类中编写一些注释映射来拥有一组用户(团队)吗? 例如:
@Entity
@Table(name = "user")
public class User implements Serializable {
@OneToMany ??????????????????????
private List<User> team;
}
答案 0 :(得分:1)
@JoinTable(name = "user_team", joinColumns = { @JoinColumn(name = "usr_id") }, inverseJoinColumns = { @JoinColumn(name = "manager_id") })
但user_team
没有utm_id
列。这很重要吗?