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

前端 未结 19 2204
感动是毒
感动是毒 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 21:17

    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 :

    List<User> result = session.createQuery("from User", User.class).getResultList();
    

    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)

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