@onetomany不在表中创建列

wbrvyc0a  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(329)

我真的一直在努力解决这个问题,但无论我尝试什么都没有用。在其他表中,它一直都是有效的,但是对于我当前正在创建的表,我想要创建的列永远不会被创建。我想要一个带有球队列表的球队表,但是在jpa中完成了这个关系之后,这个列就再也不会出现了。我做错什么了吗?下面是我如何创建表

@Entity
public class SeasonFixtures {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int SeasonFixtureID;
@OneToOne
private Season seasonId;
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name="season")
private List<Team> teams;

public int getSeasonid() {
return seasonid;
}
public void setSeasonid(int seasonid) {
this.seasonid = seasonid;
 }
 public String getSeasonName() {
return seasonName;
 }
 public void setSeasonName(String seasonName) {
this.seasonName = seasonName;
 }
 public SeasonTeams getSfid() {
return sfid;
 }
 public void setSfid(SeasonTeams sfid) {
this.sfid = sfid;
}

这是关系的另一端

@Entity
public class Team {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int Team_Id;
private String teamName;
private Blob Logo;
private String stadium;
@OneToOne
private TotalTeamStats tts;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SEASON_ID", referencedColumnName = "seasonid", unique=false)
private Season season;
public String getStadium() {
    return stadium;
}
public void setStadium(String stadium) {
    this.stadium = stadium;
}
public TotalTeamStats getTts() {
    return tts;
}
public void setTts(TotalTeamStats tts) {
    this.tts = tts;
}
public int getTeam_Id() {
    return Team_Id;
}
public void setTeam_Id(int team_Id) {
    Team_Id = team_Id;
}
public String getTeamName() {
    return teamName;
}
public void setTeamName(String teamName) {
    this.teamName = teamName;
}
public Blob getLogo() {
    return Logo;
}
public void setLogo(Blob blobs) {
    Logo = blobs;
}

但这是mysql中我的表的截图
mysql图片
如果有人能帮忙,我将不胜感激。我已经试了很久了。但我不知道还能去哪里。

thigvfpy

thigvfpy1#

您的注解或一对多关系的定义有问题。我无法提取一对多关系的定义,但我认为它应该是这样的:

@ManyToOne
@JoinColumn(name="season")
private Season season;
@OneToMany(fetch = FetchType.LAZY)

private List<Team> teams;

我不是100%确定,但我认为在一对多关系中,@joincolumn必须位于@manytone站点。
更新
可能是因为你用的是季节ID。Map与季节实体的关系,或者可能需要添加列:

@OneToOne
private Season seasonId;

到您的table上:

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "seasonId")
private Season season;

又是一个想法。

相关问题