Java 使用native=true的JPA@Query出现问题

Java 使用native=true的JPA@Query出现问题,java,jpa,Java,Jpa,我有一个奇怪的问题,我无法解决,也不知道到底出了什么问题。我有以下JPA查询 @Query(nativeQuery=true, value = "select new com.mypackage.StudentDetailsDTO(e.STUDENT_ID as studentId, e.SUBJECT_ID as subjectId, e.SUBJECT_TYPE as subjectType, "+ "e.RESULT_STATUS as resultStatus, nvl(e.ASSIGN

我有一个奇怪的问题,我无法解决,也不知道到底出了什么问题。我有以下JPA查询

@Query(nativeQuery=true, value = "select new com.mypackage.StudentDetailsDTO(e.STUDENT_ID as studentId, e.SUBJECT_ID as subjectId, e.SUBJECT_TYPE as subjectType, "+
"e.RESULT_STATUS as resultStatus, nvl(e.ASSIGNED_STUDENT_ID, -1) as assignedStudentId, nvl(e.TAKEN_BY_STUDENT_ID, -1) as takenByStudentId , count(1) as totalCount) from STUDENT e "
        + "WHERE e.STUDENT_ROLLNO = :studentRollNumber AND e.EXAM_TIME between :startTime AND :endTime ")
public List<StudentDetailsDTO> fetchStudentDetailsUsingGroupBy(@Param("studentRollNumber") String iStudentRollNumber, @Param("startTime") Date iStartTime, @Param("endTime") Date iEndTime);
这是我的DTO构造器,用于映射

public StudentDetailsDTO(long studentId, long subjectId, String subjectType, String resultStatus, String assignedStudentId, String takenByStudentId, int totalCount) {
       this.studentId = studentId;
       this.subjectId = subjectId;
       this.subjectType = subjectType;
       this.resultStatus = resultStatus;
       this.assignedStudentId = assignedStudentId;
       this.takenByStudentId = takenByStudentId;
       this.totalCount = totalCount;   
   }
每一次我都在例外之下

java.sql.SQLSyntaxErrorException: ORA-00923: FROM keyword not found where expected

任何帮助都将不胜感激,我尝试了很长时间,但没有运气。

您似乎正在使用Spring Data JPA。如果这是正确的,则不应在本机查询中调用DTO的构造函数(
new com.mypackage.studentDetailsTo()
)。您应该编写一个常见的Oracle SQL查询。SpringDataJPA将根据查询结果自动创建DTO对象

此外,DTO对象中似乎存在错误。assignedStudentId和takenByStudentId参数的类型为
String
,但您的查询选择它们为
long

java.sql.SQLSyntaxErrorException: ORA-00923: FROM keyword not found where expected