级联ALL不会为孩子组合生成ID

时间:2019-11-18 20:34:03

标签: hibernate spring-boot spring-data-jpa

我正在尝试通过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 .....

您可以在图片中看到,产品上的竞争ID为空。 Produit table screenshot 任何帮助!

0 个答案:

没有答案