Hibernate 具有JoinTable的OneToMany映射不';数据库中没有显示
我想在玩家和英雄之间建立一个1:n的关系模型。明确地说:一个玩家应该有多个英雄,而一个英雄只属于一个玩家 我的玩家类的相关摘录(除去getter、setter和无关属性)如下所示:Hibernate 具有JoinTable的OneToMany映射不';数据库中没有显示,hibernate,postgresql,hibernate-mapping,Hibernate,Postgresql,Hibernate Mapping,我想在玩家和英雄之间建立一个1:n的关系模型。明确地说:一个玩家应该有多个英雄,而一个英雄只属于一个玩家 我的玩家类的相关摘录(除去getter、setter和无关属性)如下所示: @Entity @SequenceGenerator(name = "player_id", initialValue = 1, allocationSize = 1) @Table(name = "players") public class Player { @OneToMany(cascade = Ca
@Entity
@SequenceGenerator(name = "player_id", initialValue = 1, allocationSize = 1)
@Table(name = "players")
public class Player {
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "players_heroes",
joinColumns = { @JoinColumn(name = "player_id") },
inverseJoinColumns = { @JoinColumn(name = "hero_id") })
private Set<Hero> mHeroes;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "player_id", nullable = false)
private Long mId;
}
我目前正在使用hibernate.hbm2ddl.auto=create
生成数据库架构,它提供了以下输出:
Hibernate: create table heros (hero_id int8 not null, [...] primary key (hero_id))
Hibernate: create table players (player_id int8 not null, [...], primary key (player_id))
这种联系显然缺失了:(有人能看到我做错了什么吗?好吧,只是一个在我给出的片段中看不到的愚蠢错误:失控的评论。你还需要连接表做其他事情吗?连接表通常用于多对多关联。我需要以一种有效的方式列举属于某个玩家的所有英雄。不知怎的,我认为这会LD可以更快地使用连接表而不是连接列,但这是我刚刚认识到的错误。谢谢!您应该考虑关闭这个问题,因为对进一步的读者没有帮助。
Hibernate: create table heros (hero_id int8 not null, [...] primary key (hero_id))
Hibernate: create table players (player_id int8 not null, [...], primary key (player_id))