Hibernate: select orderform0_.Id as Id2_, orderform0_.usersId as usersId2_, orderform0_.shopId as shopId2_, orderform0_.dineTime as dineTime2_, orderform0_.initalAmount as initalAm5_2_, orderform0_.finalAmount as finalAmo6_2_, orderform0_.meno as meno2_, orderform0_.cost as cost2_, orderform0_.state as state2_, orderform0_.orderType as orderType2_, orderform0_.deskAmount as deskAmount2_, orderform0_.name as name2_, orderform0_.gender as gender2_, orderform0_.tel as tel2_, orderform0_.succCount as succCount2_ from order orderform0_ where orderform0_.initalAmount=2 order by orderform0_.dineTime desc
could not execute query这是报的错误,下面是我的实体和业务方法,package com.hou.actionForm;import org.apache.struts.action.ActionForm;
public class OrderForm extends ActionForm{
public OrderForm() {}
private static final long serialVersionUID = 1L;
private String id="";
private int usersId=-1;
private String shopId="";
private String dineTime="";
private int initalAmount=-1;
private int finalAmount=-1;
private String meno="";
private Float cost;
private String state;
private String orderType;
private int deskAmount=-1;
private String name;
private String gender;
private String tel;
private Integer succCount;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}

public int getUsersId() {
return usersId;
}
public void setUsersId(int usersId) {
this.usersId = usersId;
}
public String getDineTime() {
return dineTime;
}
public void setDineTime(String dineTime) {
this.dineTime = dineTime;
}
public int getInitalAmount() {
return initalAmount;
}
public void setInitalAmount(int initalAmount) {
this.initalAmount = initalAmount;
}
public int getFinalAmount() {
return finalAmount;
}
public void setFinalAmount(int finalAmount) {
this.finalAmount = finalAmount;
}
public String getMeno() {
return meno;
}
public void setMeno(String meno) {
this.meno = meno;
}
public Float getCost() {
return cost;
}
public void setCost(Float cost) {
this.cost = cost;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getOrderType() {
return orderType;
}
public void setOrderType(String orderType) {
this.orderType = orderType;
}
public int getDeskAmount() {
return deskAmount;
}
public void setDeskAmount(int deskAmount) {
this.deskAmount = deskAmount;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public int getSuccCount() {
return succCount;
}
public void setSuccCount(int succCount) {
this.succCount = succCount;
}
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}




}<?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>
    <class name="com.hou.actionForm.OrderForm" table="order">
        <id name="id" type="string">
            <column name="Id" length="50" />
            <generator class="assigned" />
        </id>
       <property name="usersId" type="int">
          
        </property>
       
        <property name="shopId" type="string">
            
        </property>
        
        <property name="dineTime" type="string">
            
        </property>
        <property name="initalAmount" type="int">
            
        </property>
        <property name="finalAmount" type="int">
            
        </property>
        <property name="meno" type="string">
            
        </property>
        <property name="cost" type="float">
           
        </property>
        <property name="state" type="string">
           
        </property>
        <property name="orderType" type="string">
            
        </property>
        <property name="deskAmount" type="int">
            
        </property>
        <property name="name" type="string">
         
        </property>
        <property name="gender" type="string">
            
        </property>
        <property name="tel" type="string">
           
        </property>
        <property name="succCount" type="int">
        </property>
    </class>
</hibernate-mapping> public List selectInitOrder() {
   session = sessionFactory.openSession();
   
    tx = session.beginTransaction();
    System.out.println(tx);
    String hql = "from OrderForm where initalAmount=2 order by dineTime desc";
    List list = null;
    try {
        Query query = session.createQuery(hql);
        list = query.list();
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
    tx.commit();
    session.close();
    return list;
    
   }

解决方案 »

  1.   

    String hql = "from OrderForm where initalAmount=2 order by dineTime desc"; 改成
    String hql = "from OrderForm of where of.initalAmount=2 order by of.dineTime desc"; 试试
      

  2.   

    hql 语句:
    "from OrderForm of where of.initalAmount=2 order by of.dineTime desc"
    指明一下试试
      

  3.   

    刚该了下,刚才那个错误不在了,有出来这么一个,unexpected token: of near line 1, column 35 [from com.hou.actionForm.OrderForm of where of.initalAmount=2 order by of.dineTime desc]
      

  4.   

    from OrderForm o where o.initalAmount=2 order by o.dineTime desc 
    我感觉这样写更好一点吧,hQl语句好像得指明是哪个类中的哪个属性吧