Hibernate @OneToOne -- 2

来源:互联网 发布:使用数组公式计算乘积 编辑:程序博客网 时间:2024/05/21 21:49

class Person

@OneToOnepublic 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. 



0 0
原创粉丝点击