2012-10-08 72 views
0

如何創建POJO WITH ANNOTATIONS以便hibernate在映射時創建下表?一列是EE,另一列是ER休眠POJO與同一表中的兩個外鍵

CREATE TABLE friends(
    id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, 
    followee_id INT(11) UNSIGNED NOT NULL, 
    follower_id INT(11) UNSIGNED NOT NULL, 
    start_time TIMESTAMP NOT NULL, 
    end_time TIMESTAMP NOT NULL, 
    PRIMARY KEY(id), 
    KEY idx_fk_friends_followee_id (followee_id), 
    KEY idx_fk_friends_follower_id (follower_id), 
    CONSTRAINT `fk_friends_followee_id` FOREIGN KEY (followee_id) REFERENCES user (id) ON DELETE RESTRICT ON UPDATE CASCADE, 
    CONSTRAINT `fk_friends_follower_id` FOREIGN KEY (follower_id) REFERENCES user (id) ON DELETE RESTRICT ON UPDATE CASCADE 
)ENGINE=MyISAM DEFAULT CHARSET=utf8; 

回答

0

我不知道你有什麼問題,因爲這是相當直接的,我認爲:

@Entity 
public class Friend { 
    @Id 
    private Long id; 

    @ManyToOne 
    private User follower; 

    @ManyToOne 
    private User followee; 
}