简体   繁体   English

通过嵌入式ID查找的JPA存储库不起作用

[英]JPA repository find by embedded id not working

In the repository: 在存储库中:

@Transactional
public interface DeptMagrRepository extends CrudRepository<DepartmentManager, DeptMangrKey>{
  //1
  public List<DepartmentManager> findByDeptMangrKeyDepartmentDeptNo(String deptNo);
  //2
  public List<DepartmentManager> findByDeptMangrKeyEmployeeEmpNo(Integer empNo);
  //3
  public List<DepartmentManager> findByDeptMangrKey_Employee_EmpNoAndDeptMangrKey_Department_DeptNo(Integer empNo, String deptNo);
}

I was able to get correct answer using the first and second function. 我能够使用第一个和第二个功能获得正确的答案。 But the third function always returns empty result. 但是第三个函数总是返回空结果。

For example using the first function, the input is d008 which is one of the department numbers, and the result is: 例如,使用第一个功能,输入为d008,它是部门编号之一,结果为:

[
  {
    "deptMangrKey": {
  "department": {
    "deptNo": "d008",
    "deptName": "Research"
  },
  "employee": {
    "birth_date": "1959-11-09",
    "first_name": "Arie",
    "last_name": "Staelin",
    "gender": "M",
    "hire_date": "1985-01-01",
    "emp_no": 111400
  }
},
    "fromDate": "1985-01-01",
    "toDate": "1991-04-08"
  },
{
"deptMangrKey": {
  "department": {
    "deptNo": "d008",
    "deptName": "Research"
  },
  "employee": {
    "birth_date": "1952-06-27",
    "first_name": "Hilary",
    "last_name": "Kambil",
    "gender": "F",
    "hire_date": "1988-01-31",
    "emp_no": 111534
  }
},
  "fromDate": "1991-04-08",
  "toDate": "9999-01-01"
}
]

And when I call the second function, and input is 111400 which is the emp_no and I got the result: 当我调用第二个函数时,输入为111400,这是emp_no,我得到了结果:

[
  {
    "deptMangrKey": {
      "department": {
        "deptNo": "d008",
        "deptName": "Research"
      },
      "employee": {
        "birth_date": "1959-11-09",
        "first_name": "Arie",
        "last_name": "Staelin",
        "gender": "M",
        "hire_date": "1985-01-01",
        "emp_no": 111400
      }
    },
      "fromDate": "1985-01-01",
      "toDate": "1991-04-08"
  }
]

But when I call the third function, the input is 111400 and d008, and the result is empty, why will this happen???? 但是当我调用第三个函数时,输入是111400和d008,结果为空,为什么会发生这种情况?

I solve the problem, and I had a post an issue in my GitHub. 我解决了这个问题,并在GitHub上发布了一个问题。 Here is the link: https://github.com/YingcaiDong/Practical-Company-Employee-data-API/issues/6 这是链接: https : //github.com/YingcaiDong/Practical-Company-Employee-data-API/issues/6

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM