java - How to check and avoid duplicate records in a MySQL database table? -


this question has answer here:

i using spring boot, maven, hibernate , mysql

i trying determine if better programmatically find out if record exist in database --> table or if better modifying database table not allow duplicates.

any suggestions?

modify database not allow duplicates. purpose of unique constraints on tables.

why right solution? basic reason race conditions. when impose unique constraint, database checking. if try in application layer, there small gap of time between check , insert . . . , thread insert same value during time. and, have duplicate.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -