I made the username
as PRIMARY KEY in the database. Creating new account with the same username that is already in the database cause this error:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'someuser' for key 'PRIMARY'
What is the best way to work around this problem?
I tried this approach:
Query query = session.createQuery("from Account where name= :name");
query.setParameter("name", user.getUsername());
List<Account> result = query.list();
if (!result.isEmpty()) {
log.debug("User already exist");
}
However log is not triggered even if record exist in database.