Reputation: 217
I'm new to App Engine and trying to figure out how to use relationships between entities. I'm using JPA and having trouble to understand how to organize the relationships.
I have three classes City, Hotel and Attraction. I want cities to be standalone and able to be created on it's own. Every city has a list of all available hotels in the city. The hotel always need a city and can only have one city. Attractions have to have a city, but a city doesn't need to know about the attractions.
Classes:
@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
}
I've been looking all over the web, but i can't find any good tutorials on this. Would really appreciate any pointers in the right direction!
Upvotes: 1
Views: 282
Reputation: 136
There is series of posts - "JDO/JPA Snippets That Work" on appengine java google group, which is a good starting point.
This one shows how to create a bidirectional, owned, one-to-many relationship.
Upvotes: 1