JPA Hibernate merge performs insert instead of update

后端 未结 2 1888
执笔经年
执笔经年 2021-02-07 11:17

I have a simple test, where I am trying to update the object, but merge seems to be performing an insert instead of update.

@RunWith(SpringJUnit4ClassRunner.cla         


        
相关标签:
2条回答
  • 2021-02-07 11:31

    I had a version column which was not set when seed data was inserted into database. Hence all the problems with update and delete

    0 讨论(0)
  • 2021-02-07 11:38

    Merge will update the row ONLY IF it founds the id in the database, so if you create a new object and forgot to set its ID to the same ID of the desired row, it will try to insert a new one. In case your database table doesn't have any unique field, probably this insert will be successful as there will be no sql error.

    I was able to update the desired row once I set the new object with the ID of that row.

    0 讨论(0)
提交回复
热议问题