title: Problem with relation @ManyToOne in Spring Boot, Hibernate, JPA
body: <p>I have classes -&gt; Country and City.</p>
  <ol>
  <li>I wanna create works request, that when I call to get all countries, I will get all countries, with cities.</li>
  <li>When I call to get all cities, I will get all cities with only countries from Country model.</li>
  <li>I wanna add new cities with relation to countries.</li>
  </ol>
  <p>My Country model class:</p>
  <pre><code>  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Id
  private Long id;
  
  @NotEmpty(message = &quot;Name of country is mandatory.&quot;)
  @Column(unique = true)
  private String nameOfCountry;
  
  @NotBlank(message = &quot;Name of capital is mandatory.&quot;)
  private String capital;
  
  @Max(value = 17098242L, message = &quot;Maximum value for population = 10000000000&quot;)
  private Long surface;
  
  private String countryCode;
  
  private String telephoneCode;
  
  @OneToMany(cascade = CascadeType.PERSIST)
  @JoinColumn(name = &quot;country_Id&quot;, updatable = false, insertable = false)
  private List&lt;CityModelDao&gt; cityModelDao;
  </code></pre>
  <p>My City model class:</p>
  <pre><code>    @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Id
  private Long id;
  
  @NotEmpty(message = &quot;Name of country is mandatory.&quot;)
  @NotNull
  @Column(nullable = false, unique = true)
  private String nameOfCity;
  </code></pre>
  <p>I know that I don't have here @ManyToOne, but I still do it wrong and now I haven't got more ideas.</p>
  <p>My response from get countries:
  <a href="https://i.stack.imgur.com/f57oI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f57oI.png" alt="enter image description here" /></a></p>
  <p>And this is it what i want.</p>
  <p>But when i call to get cities my response is:
  <a href="https://i.stack.imgur.com/7QYcB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7QYcB.png" alt="enter image description here" /></a></p>
  <p>Unfortunately I havent got information about country.</p>
  <p>In db I have in cities information about fk from country:
  <a href="https://i.stack.imgur.com/6J7nm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6J7nm.png" alt="enter image description here" /></a></p>
  <p>Could you help me to do works relation? I ve tried something like:</p>
  <p>CityModel:</p>
  <pre><code>    @ManyToOne()
  @JoinColumn(name = &quot;country_Id&quot;)
  private CountryModelDao countryId;
  </code></pre>
  <p>CountryModel:</p>
  <pre><code>    @OneToMany(mappedBy = &quot;countryId&quot;, orphanRemoval = true, cascade = CascadeType.PERSIST)
  private List&lt;CityModelDao&gt; cityModelDao;
  </code></pre>
  <p>But it was wrong. And when I tried with above relation city, I got error.</p>
  <p>Could You tell me how to do correct @ManyToOne in this case? What I do wrong?</p>
  <p>Thanks</p>