Hibernate Mappedby Example

Hibernate Docs (2.2.5.1. One-on-One) presents the following example:

@Entity
public class Customer implements Serializable {
    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name="passport_fk")
    public Passport getPassport() {
        ...
    }

@Entity
public class Passport implements Serializable {
    @OneToOne(mappedBy = "passport")
    public Customer getOwner() {
    ...
}   

As I understand it, it Customerhas a one-to-one relationship with Passportwhere it Customeris the owner, that is, responsible for cascading updates to Passport. mappedByThe Passportindicates that it has a one-to-one relationship with Customer, but it is not responsible for cascading updates to Customer.

Customerhas a foreign key constraint on Passport, and vice versa for Passport- Customer.

What is the meaning @JoinColumn(name="passport_fk")of Customer? How about Passportin mappedByfrom Passport? Are they table columns representing their respective foreign keys?

+4
1
What is the meaning of the @JoinColumn(name="passport_fk") of Customer?

, passport_fk Customer, , (, , ).

 How about passport in the mappedBy of Passport

mappedBy, , si NOT Owner (, ). name Hibernate, FK ( Customer getPassport). .

+7

Source: https://habr.com/ru/post/1523552/


All Articles