0

如何使用 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]

4

1 回答 1

0

所选列必须出现在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 ");
于 2013-07-12T08:38:35.507 回答