我想模拟一个团队需要多种技能才能运作的事实。许多人都可以拥有某种技能。一个人有很多技能。一个人可以是许多团队的一部分。
我使用 Hibernate 来模拟这个场景。我开始构建两个实体,团队和技能,并使用 @ManyToMany 注释来链接这些依赖项。尝试添加第三个实体人是困难的地方。我不明白我应该如何构建这个模型,非常感谢任何帮助。
我没有太多使用 Hibernate 的经验,所以这是一个挑战。
我搜索了信息,我发现的大多数示例都是关于两个连接的实体,但我无法扩展这些示例以包含第三个实体。
这些是我的实体:
package com.example.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import java.util.Set;
@Entity
public class Team {
@Id
@GeneratedValue
private Long id;
private String name;
@ManyToMany
private Set<Skill> skills;
@ManyToMany
private Set<Person> persons;
}
package com.example.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import java.util.Set;
@Entity
public class Skill {
@Id
@GeneratedValue
private Long id;
private String knowHow;
@ManyToMany
private Set<Team> teams;
@ManyToMany
private Set<Person> persons;
}
package com.example.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Set;
@Entity
public class Person {
@Id
@GeneratedValue
private Long id;
private String name;
private Set<Team> teams;
private Set<Skill> skills;
}
30秒到达战场
冉冉说
交互式爱情
相关分类