当前位置: 代码迷 >> Java Web开发 >> ?使用hql查询数据库时出现以下有关问题
  详细解决方案

?使用hql查询数据库时出现以下有关问题

热度:76   发布时间:2016-04-17 16:47:56.0
求助?使用hql查询数据库时出现以下问题
javax.servlet.ServletException:   No   data   type   for   node:   org.hibernate.hql.ast.IdentNode  
  \-[IDENT]   IdentNode:   'ordId '   {originalText=ordId}


代码:
public   List   getUserOrderList(int   beginPage,   int   length,Integer   userid)   {
Session   session   =   getSession();
Transaction   tx   =   null;
tx   =   session.beginTransaction();
String   hql   =   "from   Orderlist   o1,Orderpro   o2   "   +
"where   o1.orderId   =   o2.ordId "   +
"and   o2.userId   =   "   +   userid+ ") ";
//   查询登录用户订单记录总数

Query   query   =   session.createQuery( "select   count(o1)   "   +   hql);
rowCount   =   ((Integer)   query.iterate().next()).intValue();

logger.info( "rowCount: "   +   rowCount);
this.setRowCount(rowCount);

//   查询所需页资料
query   =   session.createQuery( "from   Orderlist ");

if   (beginPage   >   0)   {
query.setFirstResult(length   *   (beginPage   -   1));
}
query.setMaxResults(length);
List   result   =   query.list();
tx.commit();
return   result;
}

配置文件如下:

<?xml   version= "1.0 "?>
<!DOCTYPE   hibernate-mapping   PUBLIC   "-//Hibernate/Hibernate   Mapping   DTD   3.0//EN "
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd ">
<!--  
        Mapping   file   autogenerated   by   MyEclipse   -   Hibernate   Tools
-->
<hibernate-mapping>
        <class   name= "com.founder.module.order.Orderpro "   table= "orderpro "   >
                <id   name= "id "   type= "java.lang.Integer ">
                        <column   name= "id "   />
                        <generator   class= "native "   />
                </id>
                <property   name= "ordId "   type= "java.lang.Integer ">
                        <column   name= "Ord_Id "   not-null= "true "   />
                </property>
                <property   name= "userId "   type= "java.lang.Integer ">
                        <column   name= "UserId "   not-null= "true "   />
                </property>
                <property   name= "prodId "   type= "java.lang.Integer ">
                        <column   name= "ProdId "   not-null= "true "   />
  相关解决方案