Checklist for updates in sleep mode

I have a table with a unique column, a "token", enforced by a unique constraint in the database. In a specific case, I need to modify an existing row to have the same token as another existing row, changing the second row to have a new value.

So let's say I have:

ID marker 0; 'aaa' 1; 'AT'

I want id 0 ('aaa') to have the 'bbb' token instead. So I need to change "bbb" to "jfeisefjse" and then I can change "aaa" to "bbb". This can be done in postgres in a single broadcast.

I tried to do the same in the code: in one transaction, I get a token from an existing line (line 1), I set it to a random value, I update the other line (line 0) to have the token of the 1st line, then I commit. However, hibernate does not follow the order in which I committed. It seems that the update statement for line 0 is run first, and postgres complains that it violates the foreign key constraint.

How can I do sleep mode? Either force a specific order of updates, or some other way to do this?

Note. Doing this in two transactions (one to scramble row 1 and then another transaction to update row 0) is not an option.

+5
source share
1

Session.flush() SQL . , "ORM" :)

+5

All Articles