无法解决休眠错误 QuerySyntaxException: designs is not mapped [from designs]

Cannot solve hibernate error QuerySyntaxException: designs is not mapped [from designs]

我正在为我的期末项目使用休眠。我有一个名为 designs 的 table 用于存储艺术品的所有细节。在探索页面中,我需要使用 hibernate 从数据库中获取所有设计。所以我创建了一个名为 designModal.java

的 java class
public class designModal {

SessionFactory sf;

public designModal() {
    sf = connection.NewHibernateUtil.getSessionFactory();

}

public String[] getAllDesigns() {
    String result[] = new String[8];
    try {
        Session ses = sf.openSession();
        Transaction tr = ses.beginTransaction();
        List<Designs> designList = ses.createQuery("from designs").list();
        for (Designs designs : designList) {
            result[0]= designs.getDesignId().toString();
            result[1]= designs.getTitle();
            result[2]= designs.getImage();
            result[3]= designs.getDescription();
            result[4]= designs.getPrice().toString();
            result[5]= designs.getViews().toString();
            result[6]= designs.getLikes().toString();
            result[7]= designs.getDesigners().toString();
        }
        tr.commit();
        ses.flush();
        ses.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println(result[0]+""+result[1]+""+result[3]);
    return result;
}

}

然后我在我的页面中调用了这个方法,

<%@page import="modal.designModal"%>
<%
    String result[] = new designModal().getAllDesigns();
    out.print(result.length);
%>

但我有一个例外:QuerySyntaxException: designs is not mapped [from designs]

我遵循了一些 SO 问题,但没有帮助。所以我创建了一个新的网络项目,但仍然没有解决。这里有什么问题?谢谢

Design.hbm.xml

    <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Oct 11, 2016 1:11:09 PM by Hibernate Tools 3.6.0 -->
<hibernate-mapping>
    <class name="pojos.Designs" table="designs" catalog="design">
        <id name="designId" type="java.lang.Integer">
            <column name="design_id" />
            <generator class="identity" />
        </id>
        <many-to-one name="designers" class="pojos.Designers" fetch="select">
            <column name="designer_id" not-null="true" />
        </many-to-one>
        <many-to-one name="galleries" class="pojos.Galleries" fetch="select">
            <column name="gallery_id" not-null="true" />
        </many-to-one>
        <property name="title" type="string">
            <column name="title" length="45" />
        </property>
        <property name="image" type="string">
            <column name="image" length="100" />
        </property>
        <property name="description" type="string">
            <column name="description" length="500" />
        </property>
        <property name="price" type="java.lang.Double">
            <column name="price" precision="22" scale="0" />
        </property>
        <property name="views" type="java.lang.Integer">
            <column name="views" />
        </property>
        <property name="likes" type="java.lang.Integer">
            <column name="likes" />
        </property>
        <set name="buysRegisters" table="buys_register" inverse="true" lazy="true" fetch="select">
            <key>
                <column name="design_id" not-null="true" />
            </key>
            <one-to-many class="pojos.BuysRegister" />
        </set>
    </class>
</hibernate-mapping>

Design.java

package pojos;
// Generated Oct 11, 2016 1:11:09 PM by Hibernate Tools 3.6.0


import java.util.HashSet;
import java.util.Set;

/**
 * Designs generated by hbm2java
 */
public class Designs  implements java.io.Serializable {


     private Integer designId;
     private Designers designers;
     private Galleries galleries;
     private String title;
     private String image;
     private String description;
     private Double price;
     private Integer views;
     private Integer likes;
     private Set buysRegisters = new HashSet(0);

    public Designs() {
    }


    public Designs(Designers designers, Galleries galleries) {
        this.designers = designers;
        this.galleries = galleries;
    }
    public Designs(Designers designers, Galleries galleries, String title, String image, String description, Double price, Integer views, Integer likes, Set buysRegisters) {
       this.designers = designers;
       this.galleries = galleries;
       this.title = title;
       this.image = image;
       this.description = description;
       this.price = price;
       this.views = views;
       this.likes = likes;
       this.buysRegisters = buysRegisters;
    }

    public Integer getDesignId() {
        return this.designId;
    }

    public void setDesignId(Integer designId) {
        this.designId = designId;
    }
    public Designers getDesigners() {
        return this.designers;
    }

    public void setDesigners(Designers designers) {
        this.designers = designers;
    }
    public Galleries getGalleries() {
        return this.galleries;
    }

    public void setGalleries(Galleries galleries) {
        this.galleries = galleries;
    }
    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
    public String getImage() {
        return this.image;
    }

    public void setImage(String image) {
        this.image = image;
    }
    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
    public Double getPrice() {
        return this.price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }
    public Integer getViews() {
        return this.views;
    }

    public void setViews(Integer views) {
        this.views = views;
    }
    public Integer getLikes() {
        return this.likes;
    }

    public void setLikes(Integer likes) {
        this.likes = likes;
    }
    public Set getBuysRegisters() {
        return this.buysRegisters;
    }

    public void setBuysRegisters(Set buysRegisters) {
        this.buysRegisters = buysRegisters;
    }
}

HibernateUtil.java

package connection;


public class NewHibernateUtil {

    private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from standard (hibernate.cfg.xml) 
            // config file.
            sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Log the exception. 
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}

变化:

List<Designs> designList = ses.createQuery("from designs").list();

至:

List<Designs> designList = ses.createQuery("from Designs d").list();