我想在前端显示带有JPA的数据库中的数据,即显示Person
的详细信息。详细信息可以是 0..n Adresse
s和 0..m Phone
s。实体如下所示:
@Entity
public class Person implements Serializable {
@Id @GeneratedValue
private int id;
private String name;
@OneToMany(mappedBy="person")
private List<Address> addresses = new ArrayList<Address>();
@OneToMany(mappedBy="person")
private List<Phone> phones = new ArrayList<Phone>();
// plus getter and setter
}
@Entity
public class Address implements Serializable {
@Id @GeneratedValue
private int id;
@ManyToOne
private Person person;
private String onestring; // plus getter and setter
}
@Entity
public class Phone implements Serializable {
@Id @GeneratedValue
private int id;
@ManyToOne
private Person person;
private String anotherstring; // plus getter and setter
}
当激活延迟加载时,......
@PersistenceContext
private EntityManager em;
public Person getPerson(int id) {
return em.find(Person .class, id);
}
...只会在adresses
和phones
上提供代理。
问题:
addresses
和phones
同时提取到Person
的同一个实例中,或者我必须两次获取Person
(addresses
一次phones
1}},有一次data-autocomplete="@Url.Action("AutoCompleteCity", "Search")"
)省略笛卡尔积?