title: JPA Query org.hibernate.QueryException: could not resolve property
body: <p>I have <code>@OneToOne</code> bi-directional relationship between following tables:</p>
  
  <pre><code>import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.OneToOne;
  import javax.persistence.Table;
  
  @Entity
  @Table
  public class StudentAccount implements DomainModel {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer idstudentaccount;
      @OneToOne(optional = false)
      @JoinColumn(name = "idstudent")
      private Student student;
      private String username;
      private String password;
      //getters and setters
  }
  
  
  
  @Entity
  @Table(name = "student")
  public class Student implements DomainModel {
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private Integer idStudent;
      private String firstname;
      private String lastname;
      @OneToOne(mappedBy = "student", cascade = CascadeType.ALL, targetEntity=StudentAccount.class)
      private StudentAccount studentAccount;
      //getters and setters
  </code></pre>
  
  <p>How to write the query to get if the username exists in the database?
  This is what i have tried:</p>
  
  <pre><code>@Transactional
  @Override
  public boolean usernameAvailability(String username, Integer studentId) {
  
      Query checkUsername = getEntityManager()
              .createQuery(
                      "SELECT COUNT(*) FROM StudentAccount s WHERE s.username=:usernameParam AND s.idstudent&lt;&gt;:accIdParam");
      checkUsername.setParameter("usernameParam", username);
      checkUsername.setParameter("accIdParam", studentId);
      long count = (long) checkUsername.getSingleResult();
      if (count &gt; 0) {
          return true;
      }
      return false;
  }
  </code></pre>
  
  <p>and i get the following exception:</p>
  
  <pre><code>java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: idstudent of: com.af.domain.StudentAccount
  </code></pre>