0

I have two tables like below. Parent and child relation.

Parent table:

parent_id is primary key auto generated

Child table:

parent_id, child_id primary keys and parent_id is foreign key

When I am trying to insert new row in primary table, child table also its inserting (working fine). When I am trying to update parent table using merge operation, in child table not able to insert new row but able to update the existing rows and getting the below error.

Cannot insert the value NULL into column parent_id, table Test.Sample.child; column does not allow nulls.

INSERT fails.

Milo
  • 3,365
  • 9
  • 30
  • 44
raj
  • 1
  • 1

1 Answers1

0

Try to use

 cascade=ALL 

annotation according to your referencing mappings.

Check here for more details. What is the difference between persist() and merge() in Hibernate?

Note: If you supply your mappings and sample usage scenario, your question can be answered more clearly.

ahmettolga
  • 996
  • 7
  • 16