我有 2 节课。父母和孩子。如下:
@Entity
@Table(name = "parent")
public class Parent implements Serializable {
private String name;
private List<Child> childs;
@OneToMany(mappedBy="parent")
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE})
public List<Child> getChilds() {
return childs;
}
@Id
@Column(name="parent_name")
public String getName() {
return name;
}
}
>
@Entity
@Table(name = "child")
public class Child implements Serializable {
@JoinColumn(name="parent_name")
private Parent parent;
public Parent getParent() {
return parent;
}
public void setParent(Parent parent) {
this.parent = parent;
}
}
当我使用 session.save(parent) 时,它将父项和子项保存在数据库中,但子表中父标识符的列将保持为空。那么问题是什么?