How to check if username already exists in table?

Solution 1:

You can use @unique annotation to store the unique values in the database and if it throws the exception for not taking the unique value the exception should be handled.