Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA - An identification variable must be provided for a range variable declaration

Tags:

java

jpa

I wonder why I got "An identification variable must be provided for a range variable declaration." error when I don't have alias.
Seems like I solved by problem when I added alias to the table.

Code with problem:

List result = entityManager.createQuery( "from Rental", Rental.class ).getResultList();

Solution:

List result = entityManager.createQuery( "from Rental r", Rental.class ).getResultList();
like image 262
richersoon Avatar asked Aug 05 '14 12:08

richersoon


1 Answers

You should make a distinction between HQL (Hibernate Query Language) and JPQL (Java Persistence Query Language). As long as your provider is Hibernate you will see no difference, but you have to remember that correct JPQL query consists of SELECT keyword. Here's explanation of this differences.

Going back to you question - it is JPQL requirement to define alias for each Entity table.

like image 178
Maciej Dobrowolski Avatar answered Nov 10 '22 10:11

Maciej Dobrowolski