当前位置: 代码迷 >> Java Web开发 >> 大神们开始觅错啦!org.hibernate.exception.SQLGrammarException: could not execute query
  详细解决方案

大神们开始觅错啦!org.hibernate.exception.SQLGrammarException: could not execute query

热度:3675   发布时间:2013-02-25 21:06:19.0
大神们开始找错啦!!org.hibernate.exception.SQLGrammarException: could not execute query
后台打印的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>

你实际表有type列么,在sql客户端上执行hql有语法错误么,
又或者type是否为关键字啊。。。很明显你的表里面有没有 type 这个列是否是数字型,  可能是关键字,你改个名字试试表的type字段没有
  相关解决方案