I\'m trying to get a list of all the users from \"users\" table and I get the following error:
org.hibernate.hql.internal.ast.QuerySyntaxException: users is
I also was importing the wrong Entity import org.hibernate.annotations.Entity;
It should be import javax.persistence.Entity;
I was getting the same error while Spring with hibernate..I was using "user" in the lowercase in my createQuery
statement and my class was User..So changed it to User in my query and problem was solved.
Query before:
Query query= em.createQuery("select u from user u where u.username=:usr AND u.password=:pass",User.class);
Query after:
Query query= em.createQuery("select u from User u where u.username=:usr AND u.password=:pass",User.class);
For example: your bean class name is UserDetails
Query query = entityManager. createQuery("Select UserName from **UserDetails** ");
You do not give your table name on the Db. you give the class name of bean.
Some Linux based MySQL installations require case sensitive. Work around is to apply nativeQuery
.
@Query(value = 'select ID, CLUMN2, CLUMN3 FROM VENDOR c where c.ID = :ID', nativeQuery = true)
There is possibility you forgot to add mapping for created Entity into hibernate.cfg.xml
, same error.
Also check that you added the annotated class using:
new Configuration().configure("configuration file path").addAnnotatedClass(User.class)
That always wasted my time when adding a new table in the database using Hibernate.