title: Where to validate uniqueness of field in Spring/Hibernate
body: <p>I am building a REST API using spring and hibernate. I have come across the issue where I want to create a user and want to know the best practice on how to validate that the user can be created.</p>
  
  <p>My controller has the @Valid annotation on the User object that gets passed into the method, and this checks for valid structure, however there is no @Unique property that gets picked up by @Valid.</p>
  
  <p>I am using the @Column(unique = true) but this throws an error at the persistence level and I feel like that is quite low level and makes it difficult to throw a custom UsernameAlreadyExistsException().</p>
  
  <p>My question here is what is the best practice in terms of preforming this type of validation. I thought about creating a custom annotation but it seems quite messy especially because as the project grows I would need multiple validators for different fields and it also seems to be closley related to tying the service layer to the annotation which seems messy</p>