MYSQL syntax error using LIMIT in Java

I am running some simple MYSQL statements from a Java application. I get a syntax error in the instruction, which seems to work fine if I run it directly against the MYSQL server via Navicat. A statement that gives me hassle:

@NamedQuery(name = "Image.findDefaultByTest", query = "SELECT i FROM Image i where (i.test_id = :test) LIMIT 0,1")

The error I am getting is:

Syntax error parsing the query [Image.findDefaultByTest: SELECT i FROM Image i where (i.test_id = :test) LIMIT 0,1], line 1, column 48: syntax error at [LIMIT].

Just to give an example of the instruction on the above line:

@NamedQuery(name = "Image.findByLocation", query = "SELECT i FROM Image i WHERE i.location = :location")

Any help on this would be greatly appreciated, the only information I can find on this through Google has been since 2003!

+4
source share
1 answer

Use @NamedNativeQuery instead of @NamedQuery .

@NamedQuery - for hql queries.

Check this out http://www.mkyong.com/hibernate/hibernate-named-query-examples/

LIMIT does not work in HQL.

+2
source

Source: https://habr.com/ru/post/1334349/


All Articles