我在父实体和子实体之间存在多对一的双向关系。问题是,当我坚持孩子时,parent_id没有坚持。其他字段都很好,但parent_id留在NULL. 我正在使用带有 Hibernate 和 mapstruct 的 Spring Data JPA 在实体和 dto 之间进行转换,如果有帮助的话。java文件如下:@Entity@Table(name = "Parent")public class ParentEntity implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; @OneToMany (fetch = FetchType.LAZY, mappedBy="parent_entity", cascade = { CascadeType.ALL }) private List<Child> children;}@Entity@Table(name = "Child")public class ChildEntity implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; @ManyToOne(optional = true) @JoinColumn(nullable = true, name = "parent_entity_id", insertable = false, updatable = false) private Parent parent_entity;}我已经尝试了一堆来自 SO 的答案,但目前无济于事。
添加回答
举报
0/150
提交
取消