Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble using @Query with Spring-Boot JPA and Java

I'm new to spring-boot and have been steadily making progress building up my project but I've come to a point where I need to execute a specific query instead of the ones built by spring.

Here is what my @Query looks like:

@Query("select top 1 * from 'table name' where 'column' like 'value' and    message like 'value' order by 'column' desc")

Due to it being work-related I had to replace our database specific information but I think you guys should still be able to get the idea of what I'm trying to do. My boss wants this query because, without it formatted like this, we are returned many results and we only want the most recent - thus the top 1 and the order by.

The error I'm seeing is "< operator> or AS expected, got '1'" and, so far, I have yet to find anything on Google.

What am I doing wrong here?

like image 932
user1818298 Avatar asked Dec 03 '22 23:12

user1818298


1 Answers

I think problem is that you wrote native query in @Query, but didn't set @Query("...", nativeQuery=true), because this annotation accepts by default queries in JPQL. Read about @Query usage there

like image 199
mexes_s Avatar answered Dec 06 '22 19:12

mexes_s