我应该如何表示这个数据库关系?

huangapple 未分类评论42阅读模式
英文:

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=&quot;increment&quot;, strategy = &quot;increment&quot;) private Long id;
@Temporal(TemporalType.TIMESTAMP) private Date timestamp;
@OneToMany private List&lt;User&gt; players;
@OneToMany private List&lt;Team&gt; teams; 

Team

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@GenericGenerator(name=&quot;increment&quot;, strategy = &quot;increment&quot;) private Long id;
@OneToMany private List&lt;User&gt; 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.

huangapple
  • 本文由 发表于 2020年7月24日 04:04:07
  • 转载请务必保留本文链接:https://java.coder-hub.com/63062301.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定