Hello,
I read some documentation about cascading, but I don't figure out my problem.
I have two entity :
The entity A have a list of entity B :
Code:
@OneToMany(mappedBy="a",fetch=FetchType.LAZY)
@Cascade({CascadeType.PERSIST})
private List<B> listB;
And the entity B have a relation with the entity A
Code:
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="a", nullable=false)
private A a;
I want to persist, no merge, the entity B when I merge or persit the entity A. So I use the annotation CascadeType.PERSIST on the list of entity B.
But when I do a merge on entity A, I have this error "object references an unsaved transient instance - save the transient instance before merging".
If I use annotation CascadeType.PERSIST and CascadeType.MERGE, this is work fine but I don't want to merge the entity B if they exist, I just want to create them...
Could someone can explain me why this doesn't work ?
Thank you for your time