I'm creating a REST API, using Spring Boot, which, using data from a table, displays random phrases.
Giving a Google, I discovered that it is possible to generate random results through pure SQL:
SELECT <coluna> FROM <tabela> ORDER BY RANDOM() LIMIT 1;
I made the H2 Bank query, which is the bank I'm using, and it worked:
TheproblemisthatSpringDatadoesnotrecognizetheSQLcommandLIMIT
.WhenIcreatethequeryinsidetherepository,throughthiscode:
public interface QuoteRepository extends JpaRepository<Quote, Integer> {
@Query("SELECT detail FROM Quote ORDER BY RANDOM() LIMIT 1")
Quote findByQuote();
Quote findByActor(String actor);
}
I get the following exception:
unexpected token: LIMIT near line 1, column 54 [SELECT detail FROM challenge.Quote ORDER BY RANDOM () LIMIT 1]
Note: The script table is mapped by the Quote
domain class.
Does anyone know of any commands that can replace LIMIT
?
Full Code in the GitHub .