Skip to content
Advertisement

Hibernate error – QuerySyntaxException: users is not mapped [from users]

I’m trying to get a list of all the users from “users” table and I get the following error:

JavaScript

This is the code I wrote to add/get users:

JavaScript

Adding users works, but when I use the getUsers function I get these error.

This is my hibernate config file:

JavaScript

and this is my User class:

JavaScript

Any idea why I get this error?

Advertisement

Answer

In the HQL , you should use the java class name and property name of the mapped @Entity instead of the actual table name and column name , so the HQL should be :

JavaScript

Update : To be more precise , you should use the entity name configured in @Entity to refer to the “table” , which default to unqualified name of the mapped java class if you do not set it explicitly.

(P.S. It is @javax.persistence.Entity but not @org.hibernate.annotations.Entity)

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement