简体   繁体   English

Jpa select 查询新的 object 给出错误

[英]Jpa select query to a new object gives error

When assign select JPA It gives an error as bellow.分配 select JPA 时会出现如下错误。 What is the issue?问题是什么?

You have an error in your SQL syntax;您的 SQL 语法有错误; 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`检查与您的 MariaDB 服务器版本相对应的手册,以了解在第 1 行的“.finance.resources.StudentForBankStatement(s.admission_no,s.first') 附近使用的正确语法

Query询问

@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 );

Helper Class助手 Class

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

In your query you have nativeQuery=true which this is not, thus the error.在您的查询中,您有nativeQuery=true这不是,因此是错误。 This should be JPQL.这应该是 JPQL。 Fix your query to something like:将您的查询修复为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM