Reputation: 43
I have two tables TableA and TableB where TableA has columns col1, col2, col3, col4, col5 and col1, col2 and col3 combine to form its primary key. TableA and TableB has one-to-many relationship on the same column(col1, col2 and col3) as its foreign key constraint. Now how can I update just col2 values in both TableA and TableB in SQL and in Hibernate?
Upvotes: 4
Views: 2939
Reputation: 48197
Doesn't matter if is hibernate or the number of columns on the primary key. You cant remove/edit a primary key value if is already use as a foreign key. That is a CONSTRAINT FK VIOLATION
, and the constraint function is precisely there to avoid any row become orphan by mistake and keep data integrity.
This need to be done in three steps:
Upvotes: 4