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)
}

}

注意:上图是改后的目录结构,之前我的命名不是这样的,才会出错,总结一下,当需要自定义存储库,一定要和本身的存储库,名称一定要对应,还有自定义存储库的实现类命名一定要规范以Impl后缀,前以自定义存储库的名称前缀。

全部评论

相关推荐

牛舌:如果我不想去,不管对方给了多少,我一般都会说你们给得太低了。这样他们就会给下一个offer的人更高的薪资了。
点赞 评论 收藏
分享
整顿职场的柯基很威猛:这种不可怕,最可怕的是夹在一帮名校里的二本选手,人家才是最稳的。
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务