1

When assign select JPA It gives an error as bellow. What is the issue?

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

@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

@Data
@AllArgsConstructor
@NoArgsConstructor
public class StudentForBankStatement
{
    private String AdmissionNo;
    private String firstName;
    private String lastName;
}
pirho
  • 11,565
  • 12
  • 43
  • 70
  • Does this answer your question? [Spring Data JPA map the native query result to Non-Entity POJO](https://stackoverflow.com/questions/29082749/spring-data-jpa-map-the-native-query-result-to-non-entity-pojo) – Stuck Jun 24 '20 at 06:41
  • I tried these solutions @Stuck but the error remain same – Tharindu Dananjaya Jun 24 '20 at 07:05

1 Answers1

1

In your query you have nativeQuery=true which this is not, thus the error. This should be 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")
pirho
  • 11,565
  • 12
  • 43
  • 70