使用注释的Hibernate组件OneToOne映射

时间:2012-09-22 17:36:39

标签: java hibernate

我有以下表格架构。

Employee (id int primary key, addressId int);
Address (id int primary key, line1 varchar(99), line2 varchar(99));

和课程:

Employee {
int id;
Address address;}

Address {
String line1;
String line2;}

如何使用注释将OneToOne组件从Employee映射到地址?

1 个答案:

答案 0 :(得分:0)

@Entity
public class Employee {

    private int id;

    @OneToOne
    private Address address;

}

@Entity
public class Address {
    private String line1;
    private String line2;
}