OneToMany association updates instead of insert
Posted
by
Shvalb
on Stack Overflow
See other posts from Stack Overflow
or by Shvalb
Published on 2013-06-26T16:20:16Z
Indexed on
2013/06/26
16:21 UTC
Read the original article
Hit count: 139
hibernate
|hibernate-mapping
I have an entity with one-to-many association to child entity.
The child entity has 2 columns as PK and one of the column is FK to the parent table.
mapping looks like this:
@OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER )
@JoinColumn(name="USER_RESULT_SEQUENCES.USER_RESULT_ID", referencedColumnName="USER_RESULT_ID", unique=true, insertable=true, updatable=false)
private List<UserResultSequence> sequences;
I create an instance of parent and add children instances to list and then try to save it to DB.
If child table is empty it inserts all children and it works perfectly. if the child table is not empty it updates existing rows!
I don't know why it updates instead of inserts, any ideas why this might happen??
Thank you!
© Stack Overflow or respective owner