1

我有一个从多个表返回结果的存储过程

CREATE DEFINER=`root`@`localhost` PROCEDURE `GetProjectAndClientOverview`()
BEGIN
  SELECT ( SELECT count(*)  FROM projects_info) as "projects_done",
    (SELECT COUNT(*) FROM client_info) as "happy_clients",
    (SELECT count(*) FROM projects_info where category_id in(
select id from pme.projects_category
where category_name in 
("Commercial","Corporate","Hospitality")
))  as "real_professionals" ,
    (SELECT COUNT(*) FROM client_info) as "cups_of_coffee";
END

我必须使用 JPA 在 SpringBoot 中调用此过程,请指导如何为此存储过程创建实体类、存储库、服务。

我试图创建实体类但不确定它是否正确

 package com.panchmeru_studio.entities;
    
    import lombok.Data;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.NamedStoredProcedureQueries;
    import javax.persistence.NamedStoredProcedureQuery;
    
    @Data
    @Entity
   @NamedStoredProcedureQueries({
    @NamedStoredProcedureQuery(name = "getProjectAndClientOverview",
                                procedureName = "GetProjectAndClientOverview",
    resultClasses ={ ProjectsInfo.class ,ClientInfo.class})
})
    public class GetProjectAndClientOverview {
        
        @Column(name="projects_done")
            private int projects_done;
        @Column(name="happy_clients")
            private int happy_clients;
        @Column(name="real_professionals")
            private int real_professionals;
        @Column(name="cups_of_coffee")
            private int cups_of_coffee;
    
        }

请更正此实体类并进一步指导我。

谢谢

4

0 回答 0