首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

错误信息:org.hibernate.exception.SQLGrammarException: could not execute query,大家帮帮忙好

2011-11-15 
异常信息:org.hibernate.exception.SQLGrammarException: could not execute query,大家帮帮忙好吗这是man

异常信息:org.hibernate.exception.SQLGrammarException: could not execute query,大家帮帮忙好吗
这是mani方法:
Session ss = HbUtil.getSession();
Transaction trans = ss.beginTransaction();
//Person per = new Person();
Query query = ss.createQuery ("from Order as order");
for (Iterator it = query.list().iterator(); it.hasNext();) 
{
Order order = (Order) it.next();
System.out.println(order.getOrderId()+"&nbsp; " + order.getMateriel()+ "<br>");
}
trans.commit();
ss.close();
System.out.println("Done");

这是hibernate实体类配置文件
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="mypage">
<class name="Order" table="t_order">
<id name="orderId" column="orderid">
<generator class="identity" />
</id>
<property name="materiel" column="materiel" />
<many-to-one name="person" class="Person" column="person" not-null="false"></many-to-one>
</class>
</hibernate-mapping>

异常详细信息
Hibernate: select order0_.orderid as orderid1_, order0_.materiel as materiel1_, order0_.person as person1_ from t_order order0_
Exception in thread "main" 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)



[解决办法]
把代码改成这样试试
Session ss = HbUtil.getSession();
Transaction trans = ss.beginTransaction();
//Person per = new Person();
Iterator it = ss.createQuery ("from Order ").list().iterator(); 
while ( it.hasNext()) 
{
Order order = (Order) it.next();
System.out.println(order.getOrderId()+"&nbsp; " + order.getMateriel()+ " <br>");
}
trans.commit();
ss.close();
System.out.println("Done");
[解决办法]
"from Order as order" ==> "from Order order"

热点排行