Jpa select 对新对象的查询给出错误

Jpa select query to a new object gives error

当分配 select JPA 时,它给出如下错误。有什么问题?

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '.finance.resources.StudentForBankStatement(s.admission_no,s.first' at line 1`

查询

@Query( value = "select NEW com.finance.resources.StudentForBankStatement(s.admission_no,s.first_name,s.last_name) from student s where branch_id = ?1", nativeQuery = true )
List<StudentForBankStatement> getStudentByClassIdBranchId( long branchId );

帮手Class

@Data
@AllArgsConstructor
@NoArgsConstructor
public class StudentForBankStatement
{
    private String AdmissionNo;
    private String firstName;
    private String lastName;
}

在您的查询中您有 nativeQuery=true 而这不是,因此是错误。这应该是 JPQL。将您的查询修改为:

@Query( value = "select NEW com.finance.resources.StudentForBankStatement(s.admissionNo, s.firstName, s.lastName) from Student s where s.branchId = :1")