这是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()+" " + 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()+" " + order.getMateriel()+ " <br>");
}
trans.commit();
ss.close();
System.out.println("Done");
------解决方案--------------------
"from Order as order" ==> "from Order order"