I have a problem, persisting a unidirectional onetomany relation.
Here is the code:
Code:
@Entity
public class Customer extends Person {
@Id
@GeneratedValue
protected Long id;
...
@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinTable(
name = "customer_addressList",
joinColumns = @JoinColumn(name = "customer_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "address_id", referencedColumnName = "id")
)
protected List<Address> addressList;
}
@Entity
public class Address extends BaseEntity {
@Id
@GeneratedValue
protected Long id;
...
}
When I create a new customer with a new addresse and persist it to the database, then the the customer and the address is saved to the database, but there is no entry in the table "customer_addressList".
When I first save the new customer to the database and then add the new (not persistent) address to the customer an update the customer, then the address will be saved and there is a new entry in the table customer_addressList.
Whats wrong by saving a new customer with a new address to the same time?