title: How to check user name if exist in database before committing to create user with Hibernate?
body: <p>Hi there is a simple login service I made with GWT, Hibernate &amp; HSQLDB.</p>
  
  <p>Right now I can create accounts, however, I need to add a functionality that will check if the username is already in the database before committing to the database. </p>
  
  <p>LoginServiceImpl.java</p>
  
  <pre><code>@Override
  public void createAccount(Account user) {
  
      try {
          Session session = HibernateUtil.getSessionFactory().getCurrentSession();
          session.beginTransaction();
          session.save(user);
          session.getTransaction().commit();
      }catch (HibernateException e) {
          e.printStackTrace();
      }catch (InvocationException e) {
          e.printStackTrace();
  
      }
  }
  </code></pre>
  
  <p>Account.java</p>
  
  <pre><code>public class Account implements Serializable {
        Long id;
        String name;
        String password;
    public Account() {
        }
        public Account(Long id) {
          this.id = id;
        }
        public String getPassword() {
          return password;
        }
        public void setPassword(String password) {
          this.password = password;
        }
        public Long getId() {
          return id;
        }
        public String getName() {
          return name;
        }
        public void setName(String name) {
          this.name = name;
        }
        public void setId(Long id) {
              this.id = id;
        }
  }
  </code></pre>