我的数据库中有 2 个表。我有一个可以有多个构建的项目。一个构建属于一个项目。一切正常,除了我的构建表中的外键保持为空。
项目
@Entity(name="project")
public class Project implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "projectID")
private Long id;
@Column
@JsonProperty("displayName")
private String name;
@JsonProperty("builds")
@JsonIgnore
@LazyCollection(LazyCollectionOption.FALSE)
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = ("project"))
private Collection<Build> builds;
public Project() {
}
public Project(String name) {
this.name = name;
}
public Collection<Build> getBuilds() {
return builds;
}
public void setBuilds(Collection<Build> builds) {
this.builds = builds;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
建造
@Entity(name = "build")
public class Build implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column
@JsonProperty("number")
private Integer number;
@Column
@JsonProperty("url")
private String url;
@JsonBackReference
@ManyToOne
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "project")
private Project project;
public Build() {
}
public Build(String url, Project project, Integer number) {
this.url = url;
this.project = project;
this.number = number;
}
public Long getId() {
return id;
}
public Integer getNumber() {
return number;
}
public String getUrl() {
return url;
}
public void setId(Long id) {
this.id = id;
}
public void setNumber(Integer number) {
this.number = number;
}
public void setUrl(String url) {
this.url = url;
}
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
}
有没有人看到问题?