I'm using SpringBoot and JPA (with Hibernate).
We can suppose that on an entity I have some unique constraints (for example, an User entity with e-mail as constraint).
When I will receive a "create" request, in case of the resource already exists, I have to return the primary-key (for example an ID, not the e-mail) of the resource that already exists.
What's the best practice to have this?
I would like to avoid 2 queries (one to check if exists and one to create), is it possible this?