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后缀,前以自定义存储库的名称前缀。

全部评论

相关推荐

想干测开的tomca...:让我来压力你!!!: 这份简历看着“技术词堆得满”,实则是“虚胖没干货”,槽点一抓一大把: 1. **项目描述是“技术名词报菜名”,没半分自己的实际价值** 不管是IntelliDoc还是人人探店,全是堆Redis、Elasticsearch、RAG这些时髦词,但你到底干了啥?“基于Redis Bitmap管理分片”是你写了核心逻辑还是只调用了API?“QPS提升至1500”是你独立压测优化的,还是团队成果你蹭着写?全程没“我负责XX模块”“解决了XX具体问题”,纯把技术文档里的术语扒下来凑字数,看着像“知道名词但没实际动手”的实习生抄的。 2. **短项目塞满超纲技术点,可信度直接***** IntelliDoc就干了5个月,又是RAG又是大模型流式响应又是RBAC权限,这堆活儿正经团队分工干都得小半年,你一个后端开发5个月能吃透这么多?明显是把能想到的技术全往里面塞,生怕别人知道你实际只做了个文件上传——这种“技术堆砌式造假”,面试官一眼就能看出水分。 3. **技能栏是“模糊词混子集合”,没半点硬核度** “熟悉HashMap底层”“了解JVM内存模型”——“熟悉”是能手写扩容逻辑?“了解”是能排查GC问题?全是模棱两可的词,既没对应项目里的实践,也没体现深度,等于白写;项目里用了Elasticsearch的KNN检索,技能栏里提都没提具体掌握程度,明显是“用过但不懂”的硬凑。 4. **教育背景和自我评价全是“无效信息垃圾”** GPA前10%这么好的牌,只列“Java程序设计”这种基础课,分布式、微服务这些后端核心课提都不提,白瞎了专业优势;自我评价那堆“积极认真、细心负责”,是从招聘网站抄的模板吧?没有任何和项目挂钩的具体事例,比如“解决过XX bug”“优化过XX性能”,纯废话,看完等于没看。 总结:这简历是“技术名词缝合怪+自我感动式凑数”,看着像“背了后端技术栈名词的应届生”,实则没干货、没重点、没可信度——面试官扫30秒就会丢一边,因为连“你能干嘛”都没说清楚。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务