我正在尝试通过spring数据将对象插入基础。有问题的对象包含一对多关系,问题是在插入子元素时,父类的标识符未插入记录中。我无法由设置员手动添加。这是我的代码:
第一个实体:
@Entity
public class Competition implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id_competition")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long identifiant;
@Column(name = "NOM_COMPETITION")
private String nomCompetition;
@Column(name = "COMPOTITION_STATUS")
private boolean competitionEtat;
private Integer points;
private LocalDateTime dateCreation;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
private List<Produit> produits;
Getters setters Constructors ...
第二个实体:
@Entity
public class Produit implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long identifiant;
private String calificationProduit;
@ManyToOne
@JoinColumn(name = "competition")
private Competition competition;
private Integer point;
Getters, Setters, Constructors .....