0
我是新的JPA,當我從複合原始鍵表中檢索到值時,我面臨異常。jpa複合主鍵表不返回值
異常描述:
Problem compiling [select t from ASSIGN_TASK_EMPLOYEE t].
[14, 34] The abstract schema type 'ASSIGN_TASK_EMPLOYEE' is unknown.
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1605)
以下是我的代碼
@Entity
@Table(name = "ASSIGN_TASK_EMPLOYEE")
//@IdClass(AssignTaskEmployeePk.class)
public class AssignTaskEmployee implements Serializable {
@EmbeddedId
private AssignTaskEmployeePk assignTaskEmployeePk;
public AssignTaskEmployeePk getAssignTaskEmployeePk() {
return assignTaskEmployeePk;
}
public void setAssignTaskEmployeePk(AssignTaskEmployeePk assignTaskEmployeePk) {
this.assignTaskEmployeePk = assignTaskEmployeePk;
}
}
@Embeddable
public class AssignTaskEmployeePk {
private String employeeId;
private String taskId;
public AssignTaskEmployeePk() {
}
@Override
public boolean equals(Object obj) {
// TODO Auto-generated method stub
if (obj instanceof AssignTaskEmployeePk) {
AssignTaskEmployeePk employeePk = (AssignTaskEmployeePk) obj;
if (!employeePk.getEmployeeId().equals(this.employeeId)) {
return false;
}
else if (!employeePk.getTaskId().equals(this.taskId)) {
return false;
}
}
else {
return false;
}
return false;
}
@Override
public int hashCode() {
return employeeId.hashCode() + taskId.hashCode() ;
}
public String getEmployeeId() {
return employeeId;
}
public void setEmployeeId(String employeeId) {
this.employeeId = employeeId;
}
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
}
我已經在數據庫中添加了四個值複合主鍵ASSIGN_TASK_EMPLOYEE(表)PK表
EMP_ID TASKID
1 2
2 4
3 5
4 6
現在我想獲得分配給emp_id 1的任務爲此我寫了下面的查詢:這應該會返回AssignTaskEmployee對象的列表。
entityManager.createQuery("select t from ASSIGN_TASK_EMPLOYEE t").getResultList()
當我執行此查詢,我得到以下異常
Exception Description:
Problem compiling [select t from ASSIGN_TASK_EMPLOYEE t].
[14, 34] The abstract schema type 'ASSIGN_TASK_EMPLOYEE' is unknown.
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1605)
非常感謝!!!!!有用!! –