title: Map entity with @SecondaryTable Annotation Spring Hibernate
body: <p>In my db I have two tables which look like this:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `Lokal` (
    `idLokal` int(11) NOT NULL AUTO_INCREMENT,
    `Ocena_idOcena` int(11) NOT NULL,
    PRIMARY KEY (`idLokal`,`Ocena_idOcena`),
    KEY `fk_Lokal_Ocena_idx` (`Ocena_idOcena`)
  )
  
  
  CREATE TABLE IF NOT EXISTS `Ocena` (
    `idOcena` int(11) NOT NULL AUTO_INCREMENT,
    `Ocena` int(1) DEFAULT NULL,
    PRIMARY KEY (`idOcena`)
  )
  </code></pre>
  
  <p>I want to map my <code>Lokal</code> entity to this <code>Ocena</code> table using <code>@SecondaryTable</code> <code>Hibernate</code> annotation, what I managed to achieve is this:</p>
  
  <pre><code>@Entity
  @Table(name="Lokal")
  @SecondaryTable(name = "Ocena", pkJoinColumns=@PrimaryKeyJoinColumn(name="Ocena_idOcena"))
  public class Lokal {
  
      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      @Column(name="idLokal")
      private int id; 
      @Column(table="Ocena" ,name="idOcena")
      private int rating;
  
      //--Getters and Setters skipped--//
  
  }
  </code></pre>
  
  <p>But all I get is an error saying:</p>
  
  <pre><code>ERROR: Unknown column 'this_1_.Ocena_idOcena' in 'on clause'
  </code></pre>
  
  <p>I think I'm misunderstanding the <code>@SecondaryTable</code> annotation, but this is my first Spring/Hibernate application so I'd be glad for any kind of help.</p>