1
我是App Engine的新手,並試圖弄清楚如何使用實體之間的關係。 我正在使用JPA,並且無法理解如何組織關係。App Engine JPA實體關係
我有三類城市,酒店和景點。我希望城市是獨立的,並且能夠獨立創建。每個城市都有一個城市所有可用酒店的列表。酒店總是需要一個城市,只能有一個城市。景點必須有一個城市,但一個城市不需要知道景點。
類:
@Entity(name = "City")
public class City {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
@OneToMany(??)
private List<Hotel> hotels;
//getters and setters
}
@Entity(name = "Hotel")
public class Hotel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key key;
private String name;
@ManyToOne(??)
private City city;
}
@Entity(name = "Attraction")
public class Attraction {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
@Unowned??
private City city;
//getters and setters
}
我一直在尋找所有網站上,但我不能找到這個任何好的教程。真的很感謝任何指向正確的方向!