I am getting an error javax.persistence.NonUniqueResultException: result returns more than one elements
while getting the EmpID
Bypass oldBypass = bypassService.getByEmployeeId(employee.getId()); //Causing a problem- Method threw 'org.springframework.dao.IncorrectResultSizeDataAccessException' exception.
ByPassService.java
Bypass getByEmployeeId(Long id);
ByPassServiceImpl.java
public Bypass getByEmployeeId(Long id) {
return bypassRepository.findByEmployeeId(id);
}
@Query("select d from Bypass d where d.employee.id = ?1 and d.isDeleted = 0")
Bypass findByEmployeeId(Long id)
This is my select statement.
Should i use the ArrayLists maybe ???
CodePudding user response:
Is your query returning only one entry? You could run it separately and check its results. Normally the employee id
should be the Primary Key in the employee
table and that would enforce uniqueness.
If you don't want the employee id
to be unique among your records, then yes, you should expect a collection of entries.