one-to-one relationship using JPA
问题 I have created two table using JPA. i need to give 1-1 relationship between these tables. Can any one tell me how to give relationship between these tables. 回答1: Simply add a column in the table "owning" the relation with a FK constraint. For example: CREATE TABLE MYENTITYA ( ID BIGINT NOT NULL, MYENTITYB_ID BIGINT ); CREATE TABLE MYENTITYB ( ID BIGINT NOT NULL ); ALTER TABLE MYENTITYA ADD CONSTRAINT SQL100326144838300 PRIMARY KEY (ID); ALTER TABLE MYENTITYB ADD CONSTRAINT SQL100326144838430