how to make a composite primary key (java persistence annotation)

前端 未结 5 1062
天命终不由人
天命终不由人 2020-11-29 06:05

How to make it so that the table user_roles defines the two columns (userID, roleID) as a composite primary key. should be easy, just can\'t remember/find.

In

5条回答
  •  半阙折子戏
    2020-11-29 06:32

    Thank you for improving your question ... and taking into account the suggestions.

    (Sorry, It is a bit strange that you postfix your entities with Daos, but it is not the point.)

    I'm not sure there is any problem left :

    • The two entities you describe each have one PK, not a pair-of.
    • The link-table has no corresponding entity, it is defined implicitely by the two entities and their ManyToMany relationship. If you need a third Entity, change your ManyToMany for a pair of OneToMany and ManyToOne relationships.

提交回复
热议问题