错误:运算符不存在:整数~~整数

时间:2015-11-06 07:19:20

标签: hibernate postgresql

我正在开发一个购物车应用程序,有一个模块用于跟踪订单使用id的顺序,数据显示在数据表中。

DAO功能:

public List OrderSearch(Integer orderSearchid) {

    List orderDetails = null;
    List itemOrders = new ArrayList();
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;
    try {
        tx = session.beginTransaction();
        Criteria cr = session.createCriteria(Orders.class);
        // Add restriction.
        cr.add(Restrictions.like("orderId", orderSearchid));
        itemOrders = cr.list();
        for (Iterator iterator1 = itemOrders.iterator(); iterator1
                .hasNext();) {
            Orders orders1 = (Orders) iterator1.next();
            System.out.println("*************************");
            System.out.println("Order ID: " + orders1.getOrderId());
            System.out.println("Order NAme: " + orders1.getOrderName());
            System.out.println("Total Price : " + orders1.getTotalPrice());

            orderDetails = orders1.getOrderDetails();
            for (Iterator iterator2 = orderDetails.iterator(); iterator2
                    .hasNext();) {
                OrderDetails orderdetailsnew = (OrderDetails) iterator2
                        .next();
                System.out.println("ORder Details Id : "
                        + orderdetailsnew.getDetailsId());

            }
        }
        tx.commit();
    } catch (HibernateException e) {
        if (tx != null)
            tx.rollback();
        e.printStackTrace();
    } finally {
        session.close();
    }
    return itemOrders;
}

orderId在数据库和pojo类中都是整数类型。 但是我收到了一个错误,

ERROR: ERROR: operator does not exist: integer ~~ integer
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 151
    org.hibernate.exception.SQLGrammarException: could not extract ResultSet
...........................................................................................

at 

com.shop.hibernate.application.ManageDAO.OrderSearch(ManageDAO.java:292)
        at com.shop.web.ItemDataBean.searchOrder(ItemDataBean.java:407)

292:itemOrders = cr.list(); 407:return searchOrders;

数据表为空,没有添加数据。请帮我解决这个问题。提前致谢

1 个答案:

答案 0 :(得分:0)

我能够解决这个问题..

我不得不给:

cr.add(Restrictions.eq("orderId", orderSearchid));

而不是

cr.add(Restrictions.like("orderId", orderSearchid));