I have a spring boot app connected to oracle DB. I am trying to order a list of records and select the top most record.
I wrote a JPA query as below but it fails.
@Query("SELECT id FROM UploadedFile uploadedFile "
+ "WHERE uploadedFile.p_file_type = 'branch' "
+ "and p_file_status='Processed' "
+ "and p_is_file_process_with_error = 0 "
+ "order by c_created_date desc "
+ "FETCH FIRST 1 rows only ")
public String findLatestBranchCodeFile();
The error received was
creating bean with name 'uploadedFileRepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.lang.String com.rhb.pintas.repo.UploadedFileRepo.findLatestBranchCodeFile()! org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: FETCH near line 1, column 204 [SELECT id FROM com.rhb.pintas.entities.UploadedFile uploadedFile WHERE uploadedFile.p_file_type = 'branch' and p_file_status='Processed' and p_is_file_process_with_error = 0 order by c_created_date desc FETCH FIRST 1 rows only ] -> [Help 1]
The issue seems to be with fetch,not sure whats wrong.