class Person
@OneToOne
public IDCard getIdcard() {
return idcard;
}
class IDCard
@OneToOne(mappedBy="idcard")
public Person getPerson() {
return person;
}
table
CREATE TABLE `idcard` (
`id` varchar(32) NOT NULL,
`createDate` datetime DEFAULT NULL,
`modifyDate` datetime DEFAULT NULL,
`bureau` varchar(255) DEFAULT NULL,
`number` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `person` (
`id` varchar(32) NOT NULL,
`createDate` datetime DEFAULT NULL,
`modifyDate` datetime DEFAULT NULL,
`age` int(11) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`idcard_id` varchar(32) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FKC4E39B5538F44A9E` (`idcard_id`),
CONSTRAINT `FKC4E39B5538F44A9E` FOREIGN KEY (`idcard_id`) REFERENCES `idcard` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
**mappedBy indicates that a bidirectional one-to-one relationship is owned by the named entity.
**The owning entity contains the primary key of the subordinate entity.