what is @JoinColumn and how it is used in Hibernate

后端 未结 5 561
死守一世寂寞
死守一世寂寞 2020-11-28 06:08

I have been reading a lot about @JoinColumn but I still don\'t get the idea behind it.

Patient Table

CREATE TABLE patient (
patient_id BIGINT NOT NUL         


        
5条回答
  •  無奈伤痛
    2020-11-28 06:33

    Vehicle Class ---- Entity @JoinColumn(name="patient_id") ---- annotation private Patient patient ----field

    Above code will generate a column patient_id (a foreign key) in Vehicle class which will point to Patient Class primary key.

    MappedBy - This attribute tells us that this relation will be managed by Vehicle class. Example. If we insert a vehicle, then two SQL will be injected if cascadetype is all/save. 1st SQL will inject details in Patient table and 2nd SQL will inject vehicle details in vehicle table with patient_id column of Vehicle column pointing to Patient tuple inserted.

提交回复
热议问题