title: One-To-Many Association without a third table
body: <p>OK, so today I tried a basic Hibernate tutorial and I'm struggling to make it behave how I want.</p>
  
  <p>This is a simple snippet, assume all other fields/methods are defined (e.g. id etc.)</p>
  
  <pre><code>@Entity
  @Table(name = "CITIES")
  public static class City {
  
      @ManyToOne
      @OnDelete(action = OnDeleteAction.CASCADE)
      private Country country;
  
  
  }
  
  
  @Entity
  @Table(name = "COUNTRIES")
  public static class Country {
  
      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
      private Set&lt;City&gt; cities;
  }
  </code></pre>
  
  <p>The above solution utilizes an (automatically created) association table - <code>COUNTRY_CITIES</code>, but
  this does work only in one way - i.e. I see country's cities (when I select one), but I don't see a city's country (when I select a city).</p>
  
  <p>So what should I do to make cities see their country?</p>
  
  <p><strong>I can add a <code>@JoinColumn(name = "COUNTRY_ID")</code> to the <code>Country.cities</code> field and it works in two ways.</strong></p>
  
  <p>But I don't like to add columns to city's table from country's code.</p>
  
  <p>So I added  the <code>@JoinColumn</code> to the <code>City.country</code> field and it didn't work.</p>
  
  <p>So - how to make the association work in 2 ways w/o an association table??</p>
  
  <hr>
  
  <p>OK, to be precise: I used the above code add feed the DB with this objects:</p>
  
  <pre><code>    Country germany = new Country("Germany", new HashSet&lt;&gt;(asList(
              new City("Berlin"),
              new City("Hamburg")
      )));
  </code></pre>
  
  <p>.. and viewed the DB. It looked like this:</p>
  
  <p><strong>table COUNTRIES_CITIES</strong> (note, I didn't declare it; Hibernate does automatically)</p>
  
  <pre><code>COUNTRIES_ID   CITIES_ID  
  1              1
  1              2
  </code></pre>
  
  <p><strong>table COUNTRIES</strong></p>
  
  <pre><code>ID      NAME  
  1       Germany
  </code></pre>
  
  <p><strong>table CITIES</strong> (note I didn't declare the COUNTRY_ID column! Hibernate again..)</p>
  
  <pre><code>ID   NAME      COUNTRY_ID  
  1    Berlin    null
  2    Hamburg   null
  </code></pre>
  
  <p>And that's it. Fetching the country gives me the cities, fetching the city gives me null country.</p>
  
  <hr>
  
  <p>If I add a <code>@JoinColumn</code> to the <code>Country</code> class, then the a column is appended to the <code>CITIES</code> table and fetching works two ways.</p>