简体   繁体   中英

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:

[
  {
    "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:

[
  {
    "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????

I solve the problem, and I had a post an issue in my GitHub. Here is the link: https://github.com/YingcaiDong/Practical-Company-Employee-data-API/issues/6

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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