我受到以下预先存在的架构定义的限制
CREATE TABLE `owner` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE `owned` (
`owner_id` bigint(20) NOT NULL,
PRIMARY KEY (`owner_id`),
CONSTRAINT `FK_blabla` FOREIGN KEY (`owner_id`) REFERENCES `owner` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
我想创建一个反映上述内容的UNIDIRECTIONAL OneToOne关系,到目前为止已经提出了以下内容
@Entity
class Owner implements Serializable {
@Id
@GeneratedValue
private Long id;
@OneToOne(cascade=CascadeType.ALL, orphanRemoval = true)
@PrimaryKeyJoinColumn
private Owned owned;
}
@Entity
class Owned implements Serializable {
@Id
@Column(name = "owner_id")
private Long ownerId;
}
但是,从上面的JPA实体定义自动生成模式时,不会生成约束
CREATE TABLE `owner` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE `owned` (
`owner_id` bigint(20) NOT NULL,
PRIMARY KEY (`owned_id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8
我错过了什么?