Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing existing rows with new ones causes duplicate key exception

everyone. I have problem replacing existing rows in table with new ones. I use JPA and PostgreSQL DB. I'm trying to delete all existing rows and then create new ones, but receive exception: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "user_destination_pk". All these actions are inside single JTA transaction. It seems that JPA doesn't delete rows before inserting, but I receive no delete exception... Any help is appreciated.

like image 788
Konstantin Milyutin Avatar asked Jan 03 '11 21:01

Konstantin Milyutin


1 Answers

Use the Hibernate Session.flush() method to flush (execute the SQL of) the deletes before saving/adding the new entities.

like image 128
araqnid Avatar answered Nov 09 '22 05:11

araqnid