No property * found for type entity!,SpringData JPA 中自定义存储库的问题,总结
问题出现,最近在学QueryDSL时,起初搭好环境后,启动i项目一直报错,No property findOffEmpCust found for type CustomersEntity!
代码示例
@Repository
public interface CustomerRepo extends JpaRepository<CustomersEntity,Long>, JpaSpecificationExecutor<CustomersEntity>, CustomerRepoCustom {
}
public interface CustomerRepoCustom {
// 自定义返回
public List<OffEmpCustVo> findOffEmpCust();
}
public class CustomerRepoCustomImpl implements CustomerRepoCustom {
@PersistenceContext
private EntityManager em;
@Override
public List<OffEmpCustVo> findOffEmpCust() {
JPAQuery<OffEmpCustVo> query = new JPAQuery<>(em);
QCustomersEntity customers = QCustomersEntity.customersEntity;
QOfficesEntity office = QOfficesEntity.officesEntity;
QEmployeesEntity employee = QEmployeesEntity.employeesEntity;
List<Tuple> list = query.select(
office.officeCode,
office.country.as("offCountry"),
office.state.as("offState"),
employee.employeeNumber.as("emploNumber"),
employee.email.as("emploEmail"),
customers.customerNumber.as("custNumber"),
customers.state.as("custState")).from(office).leftJoin(employee).on(office.officeCode.eq(employee.officeCode)).leftJoin(customers).on(employee.employeeNumber.eq(customers.salesRepEmployeeNumber)).fetchResults().getResults();
List<OffEmpCustVo> voList = list.stream().map(r -> JSONUtil.toBean(JSONUtil.toJsonStr(r), OffEmpCustVo.class)).collect(Collectors.toList());
return voList;
// select off.officeCode , off.country, off.state , em.employeeNumber, em.email, cu.customerNumber , cu.state from offices off left outer join employees em on (off.officeCode=em.officeCode) left outer join customers cu on (em.employeeNumber=cu.salesRepEmployeeNumber)
}
}