Hibernate一对一的关系

时间:2014-09-30 13:05:29

标签: java hibernate relational-database one-to-one hibernate-annotations

假设我们有一个名为LatLng的类:

public class LatLng {

    private long id;
    private double latitude;
    private double longitude;

    //setters & getters

}

如下图所示:

enter image description here

我们在PoliceStationLatLng

之间存在一对一的关系

以及HotelLatLng

之间的一对一关系

依旧......

我们如何在休眠中创建这样的关系? (注释和xml映射)

1 个答案:

答案 0 :(得分:0)

您需要的是实体之间的双向一对一关联。

检查以下链接:

Hibernate - bidirectional @OneToOne

Hibernate bidirectional using mapping files.

按照链接尝试创建您的实体。