I've multiples threads consulting a database at the same time in order to verify if an entry already exists. If no: insert a entry. If yes: do nothing.
My PK is serial, and the verification of consulting described before is doing by other 2 fields (operation-number, company-id).
The problem is that at the some times I'm caught in race condition, resulting in duplicated entries.
Please, the only way to avoid that is using a composite PK (serial-id, operation-number, company-id)? Am I right? Any thoughts?
PS: I'm using Java, Hibernate and PostgreSQL.
Thx.