Spring JpaRepositroy.save() does not appear to throw exception on duplicate saves

后端 未结 4 1829
遇见更好的自我
遇见更好的自我 2020-12-09 02:36

I\'m currently playing around on Spring boot 1.4.2 in which I\'ve pulled in Spring-boot-starter-web and Spring-boot-starter-jpa.

My main issue is that when I save a

4条回答
  •  死守一世寂寞
    2020-12-09 03:25

    I think you are aware of CrudRepository.save() is used for both insert and update. If an Id is non existing then it will considered an insert if Id is existing it will be considered update. You may get an Exception if your send the Id as null.

    Since you don't have any other annotations apart from @Id on your id variable, The Unique Id generation must be handled by your code Or else you need to make use of @GeneratedValue annotation.

提交回复
热议问题