【问题标题】:selecting records from tables using HQL Query..........@使用 HQL 查询从表中选择记录............@
【发布时间】:2013-07-10 18:00:43
【问题描述】:

如何使用 HQL 查询从多个表中选择记录..

    Session session=dao.getSessionFactory().openSession();

    Query query=session.createQuery("from b.Customer_name PurchaseDetailBean p,BookingBean b where p.Booking_Id=b.Booking_Id ");


    System.out.println("dlkkdc"+query);

    arg0.getPortletSession().setAttribute("query", query);

      Query q1 = (Query) arg0.getPortletSession().getAttribute("query");
      Gson gson = new Gson();


    System.out.println("***" + gson.toJson(q1.list()));
    arg0.getPortletSession().setAttribute("adminsales", gson.toJson(q1.list()));
    System.out.println("iiiiiiiiiiiiiiiiiiiiiiii"+gson.toJson(q1.list()));

ITZ 显示错误::

org.hibernate.hql.ast.QuerySyntaxException:意外令牌:p 靠近第 1 行,第 41 列 [来自 b.Customer_name PurchaseDetailBean p,Com.bean.BookingBean b where p.Booking_Id=b.Booking_Id]

【问题讨论】:

    标签: hql


    【解决方案1】:

    所选列必须出现在 from

    之前

    所以,从

    更改您的 查询
    Query query=session.createQuery
       ("from b.Customer_name PurchaseDetailBean p,BookingBean b where p.Booking_Id=b.Booking_Id ");
    

    Query query=session.createQuery
       ("b.Customer_name from PurchaseDetailBean p,BookingBean b where p.Booking_Id=b.Booking_Id ");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-20
      • 2014-11-21
      相关资源
      最近更新 更多