Bidirectional relationship

Report a typo

There are the following two entities:

Person to EmailAddress relationship diagram

A person can have many email addresses, but an email address can belong to only one person. There are corresponding JPA entities with a bidirectional relationship:

Java
@Entity
public class Person {

    @Id
    private int id;

    private String name;

    {1}(mappedBy = "{2}")
    private List<EmailAddress> emailAddressess;
}

@Entity
public class EmailAddress {

    @Id
    private int id;

    private String name;

    @ManyToOne
    {3}({4} = "person_id")
    private Person person;
}
Kotlin
@Entity
class Person(

    @Id
    var id: Int = 0,

    var name: String? = null,

    {1}(mappedBy = "{2}")
    var emailAddresses: MutableList<EmailAddress> = ArrayList()
)

@Entity
class EmailAddress(

    @Id
    var id: Int = 0,

    var name: String? = null,

    @ManyToOne
    {3}({4} = "person_id")
    var person: Person? = null
)

Match the missed annotations and their parameters.

Match the items from left and right columns
1
2
3
4
@OneToMany
person
name
@JoinColumn
___

Create a free account to access the full topic