【发布时间】:2018-05-21 07:04:54
【问题描述】:
要从具有主键的实体中查找对象,我们使用em.find(Person.class, <Id>)。
我正在使用 JPA EclipseLink,并且我有一个具有复合主键 (@classId) 的 Person 实体,
Person 实体:
@Entity
@IdClass(PersonId.class)
public class Person {
@Id
private int id;
@Id
private String name;
public String getName() {
return name;
}
// getters & setters
}
和 PersonID:
public class PersonId implements Serializable {
private static final long idVersionUID = 343L;
private int id;
private String name;
// must have a default construcot
public PersonId() {
}
public PersonId(int id, String name) {
this.id = id;
this.name = name;
}
//getters & setters
//hachCode & equals
}
如何使用 em.find 获取 Person 对象?
【问题讨论】:
标签: jpa eclipselink jpql entitymanager