Unidirectional relationship

Report a typo

There are the following two entities:

County to city relationship diagram

One country can have many cities and a city can belong to only one country. There are corresponding JPA entities with a unidirectional relationship:

Java
@Entity
public class Country {

    @Id
    private int id;

    private String name;

    {1}
    {2}(name = {3})
    private List<City> cities;
}

@Entity
public class City {

    {4}
    private int id;

    private String name;
}
Kotlin
@Entity
class Country(

    @Id
    var id: Int = 0,

    var name: String? = null,

    {1}
    {2}(name = {3})
    var cities: MutableList<City> = ArrayList()
)

@Entity
class City(

    {4}
    var id: Int = 0,

    var name: String? = null
)

Match the missed annotations and their parameters.

Match the items from left and right columns
1
2
3
4
@JoinColumn
@Id
@OneToMany
"country_id"
___

Create a free account to access the full topic