Reputation: 255
I am trying to persist entities with @OneToMany and @ManyToOne relationships.
@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;
problem is that it inserts NULL instead of customer_id in the address
table.
could you suggest why is that happening.
Thank you in advance.
Upvotes: 3
Views: 724
Reputation: 691735
That probably means that you didn't initialize the customer
field of the addresses. If that isn't the solution, then show us your code.
Upvotes: 4