java.lang.IllegalArgumentException:org.hibernate.hql.internal.ast.QuerySyntaxException

时间:2019-02-15 08:48:39

标签: java spring hibernate jpa

我在Spring Boot和Hibernate方面遇到一些问题,我想告诉你我对Java还是很陌生。我已经开始用Java编写一个小程序,试图在使用JPA的同时从数据库中获取结果我陷入了以下错误

错误

Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: DC_NOTIF_EVNT_ORG_CONFIG is not mapped [select count(*) from DC_NOTIF_EVNT_ORG_CONFIG C JOIN DC_NOTIF_EVNT_ORG_PERS B ON B.NOTIF_EVNT_ORG_CONFIG_ID=C.NOTIF_EVNT_ORG_CONFIG_ID JOIN GRR_PARTY GRR ON GRR.PERS_ID =B.PERS_ID   
JOIN DC_NOTIF_EVNT_CONFIG D ON C.NOTIF_EVNT_CONFIG_ID=D.NOTIF_EVNT_CONFIG_ID JOIN DC_SCHED_FREQ_CONFIG E ON E.SCHED_FREQ_CONFIG_ID= C.SCHED_FREQ_CONFIG_ID JOIN DC_NOTIF_EVNT_SCHED F
ON F.NOTIF_EVNT_SCHED_ID=C.NOTIF_EVNT_SCHED_ID JOIN DC_ORG G ON C.ORG_ID=G.ORG_ID WHERE C.ORG_ID=:orgId AND GRR.PERS_ID=:persId AND E.STRT_DT=:strtDt AND C.ACT_IND=1]

代码 main.java

    @SpringBootApplication
public class NotificationApplication {
           @Autowired
           private startTimeRepo repo;
           public static void main(String[] args) { 

                 SpringApplication.run(NotificationApplication.class, args);

                 List<Abc_Notification> es = repo.ifNotificationExst(dto.getOrgId(),dto.getUsers().get(0).getPersId(),dto.getScheduler().getStartDate());
                System.out.println(es);


           }

startTimeRepo.java

  package com.abc.dc.notification.dao;

    import com.abc.dc.notification.dao.model.Abc_Notification;
    import org.springframework.data.jpa.repository.JpaRepository;
    import org.springframework.data.jpa.repository.Query;
    import org.springframework.data.repository.query.Param;
    import org.springframework.stereotype.Repository;

    import java.util.List;

    @Repository
    public interface startTimeRepo extends JpaRepository<Abc_Notification, Integer> {
        @Query(value = "select count(*) from DC_NOTIF_EVNT_ORG_CONFIG C JOIN DC_NOTIF_EVNT_ORG_PERS B ON B.NOTIF_EVNT_ORG_CONFIG_ID=C.NOTIF_EVNT_ORG_CONFIG_ID JOIN GRR_PARTY GRR ON GRR.PERS_ID =B.PERS_ID   
JOIN DC_NOTIF_EVNT_CONFIG D ON C.NOTIF_EVNT_CONFIG_ID=D.NOTIF_EVNT_CONFIG_ID JOIN DC_SCHED_FREQ_CONFIG E ON E.SCHED_FREQ_CONFIG_ID= C.SCHED_FREQ_CONFIG_ID JOIN DC_NOTIF_EVNT_SCHED F
ON F.NOTIF_EVNT_SCHED_ID=C.NOTIF_EVNT_SCHED_ID JOIN DC_ORG G ON C.ORG_ID=G.ORG_ID WHERE C.ORG_ID=:orgId AND GRR.PERS_ID=:persId AND E.STRT_DT=:strtDt AND C.ACT_IND=1", nativeQuery = true)
        List<Abc_Notification> orgnId(@Param("orgId") Long orgId, @Param("persId") Long persId, @Param("strtDt") LocalDate strtDt);

    }

服务类:Abc_NotificationScheduleTimeService.java

package com.iqvia.dc.notification.service;

import com.iqvia.dc.notification.dao.model.Abc_Notification;
import com.iqvia.dc.notification.dao.startTimeRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Abc_NotificationScheduleTimeService {

    @Autowired
    private startTimeRepo starttimeRepo;

    public Abc_Notification orgnId(Integer orgId){
        return  starttimeRepo.orgnId(abcorgIdId);
    }
    public Abc_Notification persIdn(Integer persId){
        return  starttimeRepo.persIdn(persId);
    }
    public Abc_Notification strtnDt(Integer strtDt){
        return  starttimeRepo.strtnDt(strtDt);
    }

}

1 个答案:

答案 0 :(得分:0)

在这一部分:

@Query(value = "select count(*) from ...", nativeQuery = true)
        List<Abc_Notification> orgnId(@Param("orgId") Long orgId, @Param("persId") Long persId, @Param("strtDt") LocalDate strtDt);

未完成映射。查询的结果类型可以是例如Long,但不能是实体列表。