title: spring data jpa tables joining by One to one Association
body: <p>I am trying to join two tables and display its result by using spring data JPA one to one association. Below I am Adding my Model and repository classes,
  My first model class Users is ,</p>
  
  <pre><code>@Entity
  @Table(name = "users")
  
  public class Users implements Serializable{
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Integer id;
  
  @Column(name = "username")
  public String username;
  
  @Column(name = "password")
  public String password;
  
  @Column(name = "privid")
  public Integer privid;
  
  @OneToOne()
  @JoinColumn(name="join_privillage")
  private Privillages priviJoin;
  
  
  public Integer getId() {
      return id;
  }
  
  public void setId(Integer id) {
      this.id = id;
  }
  
  public String getUsername() {
      return username;
  }
  
  public void setUsername(String username) {
      this.username = username;
  }
  
  public String getPassword() {
      return password;
  }
  
  public void setPassword(String password) {
      this.password = password;
  }
  
  public Integer getPrivid() {
      return privid;
  }
  
  public void setPrivid(Integer privid) {
      this.privid = privid;
  }
  
  public Privillages getPriviJoin() {
      return priviJoin;
  }
  
  public void setPriviJoin(Privillages priviJoin) {
      this.priviJoin = priviJoin;
  }
  
  
  
  protected Users() {
  }
  
  public Users(String username, String password, Integer privid) {
      this.username = username;
      this.password = password;
      this.privid = privid;
  }
  @Override
  public String toString() {
      return String.format("Users[id=%d, username='%s', password='%s']", id, 
  username, password);
  }
  }
  </code></pre>
  
  <p>And my next Model class that I need to join is:</p>
  
  <pre><code>@Entity
  @Table(name = "privillages")
  public class Privillages implements Serializable {
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  public  Integer id;
  
  @Column(name = "privid")
  public Integer privid;
  
  @Column(name = "privi_name")
  public String privi_name;
  
  @OneToOne(fetch=FetchType.LAZY, mappedBy="priviJoin")
  public Users user;
  
  
  public Integer getId() {
      return id;
  }
  
  public void setId(Integer id) {
      this.id = id;
  }
  
  public Integer getPrivid() {
      return privid;
  }
  
  public void setPrivid(Integer privid) {
      this.privid = privid;
  }
  
  public String getPrivi_name() {
      return privi_name;
  }
  
  public void setPrivi_name(String privi_name) {
      this.privi_name = privi_name;
  }
  
  public Users getUser() {
      return user;
  }
  
  public void setUser(Users user) {
      this.user = user;
  }
  
  public Privillages() {
  }
  
  public Privillages(Integer privid, String privi_name ) {
      this.privid = privid;
      this.privi_name = privi_name;
  
  }
  }
  </code></pre>
  
  <p>And my repository is:</p>
  
  <pre><code>public interface UsersRepository extends CrudRepository&lt;Users, Integer&gt; {
  
  @Query("SELECT u.username FROM Users u inner join p.privi_name FROM 
  Privillages p")
  List&lt;Users&gt; findByUsername();
  }
  </code></pre>
  
  <p>And when I am running application , its hows the error like </p>
  
  <blockquote>
    <p>"unexpected token: FROM near line 1, column 74 [SELECT u.username FROM
    com.central.model.Users u inner join p.privi_name FROM
    com.central.model.Privillages p]".</p>
  </blockquote>
  
  <p>And </p>
  
  <blockquote>
    <p>" Validation failed for query for method public abstract
    java.util.List
    com.central.repository.UsersRepository.findByUsername()!".</p>
  </blockquote>