后台打印的hql语句:
Hibernate: 
    select
        dishes0_.id as id2_,
        dishes0_.DishesName as DishesName2_,
        dishes0_.DishesType as DishesType2_,
        dishes0_.price as price2_,
        dishes0_.type as type2_ 
    from
        myshop.DISHESNAME dishes0_
实现DAO: public List<Dishes> getAll() {
try {
String hql="from Dishes";
Query query = session.createQuery(hql);
return query.list();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}hibernate配置文件:<hibernate-mapping>
    <class name="com.shop.bean.Dishes" table="DISHESNAME" schema="myshop">
        <id name="id" type="java.lang.Integer">
            <column name="id" precision="20" scale="0" />
            <!-- <generator class="sequence"> 
       <param name="sequence">Sequence_Order</param> 
    </generator> -->
    <generator class="identity" /> 
        </id>
        
        <property name="dishesName" type="java.lang.String">
            <column name="DishesName" />
        </property>
        
        <property name="dishesType" type="java.lang.Integer">
            <column name="DishesType" />
        </property>
        
        <property name="price" type="java.lang.Double">
            <column name="price" />
        </property>
        
        <property name="type" type="java.lang.Integer">
            <column name="type" />
        </property>
    </class>
</hibernate-mapping>

解决方案 »

  1.   

    后台报的错
    报的错:
    org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.loader.Loader.doList(Loader.java:2223)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
    at org.hibernate.loader.Loader.list(Loader.java:2099)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    at com.shop.dao.impl.DishesDaoImpl.getAll(DishesDaoImpl.java:63)
    at com.shop.biz.impl.DishesBizImpl.getAll(DishesBizImpl.java:42)
    at com.shop.action.DishesAction.dishesSelect(DishesAction.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
    at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
    at com.shop.util.LoginInterceptor.intercept(LoginInterceptor.java:24)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
      

  2.   

    Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'dishes0_.type' in 'field list'
      

  3.   

    你实际表有type列么,在sql客户端上执行hql有语法错误么,
    又或者type是否为关键字啊
      

  4.   

    很明显你的表里面有没有 type 这个列是否是数字型,  可能是关键字,你改个名字试试
      

  5.   

    你的配置文件里面的字段对应错了,name是实体类里面的属性,column对应着表的列名,很明显你type这里写错了