I have classes -> Country and City.
- I wanna create works request, that when I call to get all countries, I will get all countries, with cities.
- When I call to get all cities, I will get all cities with only countries from Country model.
- I wanna add new cities with relation to countries.
My Country model class:
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
private Long id;
@NotEmpty(message = "Name of country is mandatory.")
@Column(unique = true)
private String nameOfCountry;
@NotBlank(message = "Name of capital is mandatory.")
private String capital;
@Max(value = 17098242L, message = "Maximum value for population = 10000000000")
private Long surface;
private String countryCode;
private String telephoneCode;
@OneToMany(cascade = CascadeType.PERSIST)
@JoinColumn(name = "country_Id", updatable = false, insertable = false)
private List<CityModelDao> cityModelDao;
My City model class:
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
private Long id;
@NotEmpty(message = "Name of country is mandatory.")
@NotNull
@Column(nullable = false, unique = true)
private String nameOfCity;
I know that I don't have here @ManyToOne, but I still do it wrong and now I haven't got more ideas.
My response from get countries:

And this is it what i want.
But when i call to get cities my response is:

Unfortunately I havent got information about country.
In db I have in cities information about fk from country:

Could you help me to do works relation? I ve tried something like:
CityModel:
@ManyToOne()
@JoinColumn(name = "country_Id")
private CountryModelDao countryId;
CountryModel:
@OneToMany(mappedBy = "countryId", orphanRemoval = true, cascade = CascadeType.PERSIST)
private List<CityModelDao> cityModelDao;
But it was wrong. And when I tried with above relation city, I got error.
Could You tell me how to do correct @ManyToOne in this case? What I do wrong?
Thanks