我有2個表。第二個表包含兩個FK到第一個(其含義是用戶可以有一組其他用戶)。如何在Hibernate中註釋具有相同類型實體的實體
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;
}
可能的重複 - http://stackoverflow.com/a/3393662/738746 –
據我所知在這個例子中有一個表。但我有兩張桌子。 – irko