英文:
How would I represent this database relation?
问题
我确信这很基础,但我对数据库关系了解不多。
示例:一个游戏拥有用户,每个用户在特定游戏中都有一个角色。用户在不同的游戏中拥有不同的角色。
我还需要每个用户在每个游戏中都有一个团队。
用户
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@GenericGenerator(name="increment", strategy = "increment")
private Long id;
@Temporal(TemporalType.TIMESTAMP) private Date timestamp;
@OneToMany private List<User> players;
@OneToMany private List<Team> teams;
团队
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@GenericGenerator(name="increment", strategy = "increment")
private Long id;
@OneToMany private List<User> players;
private int maxSize;
private int type;
用户
除了 id 和用户名,没有任何字段。
我不明白如何在每个游戏中为用户分配角色,也不认为我有一个很好的方法将玩家加入团队。
我对如何表示这种关系感到有些困惑,希望能得到一些指导。
英文:
I'm sure that this is basic but I don't know much about database relations.
Example: A Game has Users that each have a Role within the specific Game. Users have different Roles in different Games.
I also need each User to be on a team for each game.
User
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@GenericGenerator(name="increment", strategy = "increment") private Long id;
@Temporal(TemporalType.TIMESTAMP) private Date timestamp;
@OneToMany private List<User> players;
@OneToMany private List<Team> teams;
Team
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@GenericGenerator(name="increment", strategy = "increment") private Long id;
@OneToMany private List<User> players;
private int maxSize;
private int type;
User
doesn't have any fields except for id and username
I don't understand how I can give Users a role in each game and I don't think I have a good way of including players in teams.
I'm kind of lost about how to represent the relationship, any guidance is appreciated.
专注分享java语言的经验与见解,让所有开发者获益!
评论