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

前端 未结 19 2203
感动是毒
感动是毒 2020-11-30 20:14

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          


        
相关标签:
19条回答
  • 2020-11-30 20:52

    I also was importing the wrong Entity import org.hibernate.annotations.Entity; It should be import javax.persistence.Entity;

    0 讨论(0)
  • 2020-11-30 20:54

    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);
    
    0 讨论(0)
  • 2020-11-30 20:55

    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.

    0 讨论(0)
  • 2020-11-30 20:57

    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)
    
    0 讨论(0)
  • 2020-11-30 20:58

    There is possibility you forgot to add mapping for created Entity into hibernate.cfg.xml, same error.

    0 讨论(0)
  • 2020-11-30 20:59

    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.

    0 讨论(0)
提交回复
热议问题