次のスキーマを持つ Person と Address の 2 つのテーブル (作成済み) があります。
create table Person (
`id` int(11) not null auto_increment,
`name` varchar(255) default null,
primary key(`id`)
)
create table Address (
`id` int(11) not null,
`city` varchar(255) default null,
primary key (`id`),
constraint foreign key (`id`) references `Person`(`id`)
)
では、コードでどの注釈を使用すればよいでしょうか?
両方のクラスのスケルトンは次のとおりです。
class Person {
@Id @GeneratedValue
@Column(name="id")
int id;
String name;
Address address;
}
class Address {
int id;
}
PersonクラスのaddressフィールドとAddressクラスのidフィールドに注釈を追加する必要があります。