0

I am having a trouble with my codes. If I input correct criteria, let say 300 for the amount it returns correct result/s.But if I put not qualified search criteria it still return result/s which is incorrect.

@Override
public Page<ApPayment> searchPayment(final String searchCriteria,
    final PageSetting pageSetting) {
HibernateCallback<Page<ApPayment>> paymentCallBack = new     HibernateCallback<Page<ApPayment>>() {
    @Override
    public Page<ApPayment> doInHibernate(Session session)
            throws HibernateException, SQLException {
        Criteria criteria =  session.createCriteria(ApPayment.class);
        if(!searchCriteria.isEmpty() && StringFormatUtil.isNumeric(searchCriteria)) {

            Integer paymentNo = Integer.valueOf(searchCriteria);
            Double amount = Double.valueOf(searchCriteria);

            criteria.add(Restrictions.or(Restrictions.like(ApPayment.FIELD.paymentNumber.name(), paymentNo), Restrictions.eq(ApPayment.FIELD.amount.name(), amount)));
        }
        Page<ApPayment> payments = getAll(criteria, pageSetting);
        for (ApPayment payment: payments.getData()) {
            --some codes--
        }
        return payments;
     }
  };
  return getHibernateTemplate().execute(paymentCallBack);
}

Thanks in advance.

kwan_ah
  • 1,061
  • 1
  • 12
  • 18
  • What do you mean by _not qualified_? – Sotirios Delimanolis Jun 11 '13 at 01:46
  • Any value that does not match in my record of payments. For example, payment1(paymentNo=12345, amount=500). If I will input "opii9090" it should return nothing. In my case, it still return the payment1 data. – kwan_ah Jun 11 '13 at 03:30
  • Can you show us what `getAll(criteria, pageSetting)` does? – Sotirios Delimanolis Jun 11 '13 at 13:42
  • This part looks highly suspicious: `Integer paymentNo = Integer.valueOf(searchCriteria); Double amount = Double.valueOf(searchCriteria);` You are using the same string and parsing two different values. – lunr Jun 11 '13 at 15:46

0 Answers0