3
votes

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.

1
Please show the complete mappings (without constructors and methods) plus the code you use to persist. -> edit questionKawu
a little code will actually performs the transaction will be helpful!Satadru Biswas
It's just a blind shooting here if you don't show us the code for the actual persistence operation.Piotr Nowicki

1 Answers

4
votes

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.