Issue
I am using JPArepository.save() to insert the record to the database but it will automatically update the existing record in the database. What I want to do is let it throw exception if there are records with same primary key in the database.
I searched the solution in Google and find a solution that said use saveAndFlush instead of save can solve it. However, it still update the existing record after I used saveAndFlush.
Solution
Finally, I've found the solution. I just implement Persistable interface and ovrride the isNew() to be always true.
Answered By - Michael Tsai
Answer Checked By - Marie Seifert (JavaFixing Admin)