我正在尝试保留具有@OneToMany 和@ManyToOne 关系的实体。
@OneToMany(mappedBy="customer", cascade=CascadeType.ALL, fetch=FetchType.EAGER)
private Collection<Address> addresses = new LinkedHashSet<Address>();
@ManyToOne
@JoinColumn(name="customer_id", referencedColumnName="customer_id")
private Customer customer;
问题是它在 address
表中插入了 NULL 而不是 customer_id。
你能说说为什么会这样吗。
提前谢谢你。
最佳答案
这可能意味着您没有初始化地址的 customer
字段。如果这不是解决方案,请向我们展示您的代码。
关于JPA 坚持 OneToMany ManyToOne,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8240450/