@oneToMany 級聯保存 多的一方自動保存外鍵

from stackoverflowspring

If the relationship is not bidirectional, try to use @JoinColumn in this case, and test. Remove mappedBy and add @JoinColumn – Ankur Singhal Nov 27 '14 at 3:45app

@Entity
@Data
@DynamicUpdate
public class Family {

    @Id
    private int id;

    @OneToMany(cascade = CascadeType.ALL)
    @JoinColumn
    private List<Parent> parents;
    
}
@Entity
@Data
@DynamicUpdate
public class Parent {


    @Id
    private int id;

    @ManyToOne(cascade = CascadeType.ALL)
    @JsonIgnore
    private Family family;

}
相關文章
相關標籤/搜索