title: Hibernate, Spring and foreign keys
body: <p>I'm working on a hibernate, spring project to help me understand the basics of those two.
  I'm running into a problem where i want to be able to add foreign keys to my tables.</p>
  
  <p>I've been browsing the internet for information regarding this subject and I haven't been able to find something that suits my needs.</p>
  
  <p>I have two classes:</p>
  
  <pre><code> Schools
   Classes
  </code></pre>
  
  <p>Now i want to map the primary key from Schools to Classes.</p>
  
  <p>This is the code I have now:</p>
  
  <pre><code>@ManyToOne
  @JoinColumn(name = "SCHOOL_ID", table = "SCHOOL")
  private School school;
  </code></pre>
  
  <p>and for my getter and setter:</p>
  
  <pre><code>public long getSchool() {
      return school.getId();
  }
  
  public void setSchool(long schoolId) {
      this.school.setId(schoolId);
  }
  </code></pre>
  
  <p>Is this the way to go? Or am I totally looking at it the wrong way.</p>
  
  <p>Thanks!</p>