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

前端 未结 19 2236
感动是毒
感动是毒 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:07

    Added @TABLE(name = "TABLE_NAME") annotation and fixed. Check your annotations and hibernate.cfg.xml file. This is the sample entity file that works:

    import javax.persistence.*;
    
    @Entity
    @Table(name = "VENDOR")
    public class Vendor {
    
        //~ --- [INSTANCE FIELDS] ------------------------------------------------------------------------------------------
        private int    id;
        private String name;
    
        //~ --- [METHODS] --------------------------------------------------------------------------------------------------
        @Override
        public boolean equals(final Object o) {    
            if (this == o) {
                return true;
            }
    
            if (o == null || getClass() != o.getClass()) {
                return false;
            }
    
            final Vendor vendor = (Vendor) o;
    
            if (id != vendor.id) {
                return false;
            }
    
            if (name != null ? !name.equals(vendor.name) : vendor.name != null) {
                return false;
            }
    
            return true;
        }
    
        //~ ----------------------------------------------------------------------------------------------------------------
        @Column(name = "ID")
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Id
        public int getId() {
            return id;
        }
    
        @Basic
        @Column(name = "NAME")
        public String getName() {
    
            return name;
        }
    
        public void setId(final int id) {
            this.id = id;
        }
    
        public void setName(final String name) {    
            this.name = name;
        }
    
        @Override
        public int hashCode() {
            int result = id;
            result = 31 * result + (name != null ? name.hashCode() : 0);
            return result;
        }
    }
    

提交回复
热议问题