0

I have a problem in named query got error org.hibernate.HibernateException: Errors in named queries: customers.amountDeposit, customers.amountWithdraw

Here is my Namedqueries of deposit and withdrawal of amount and DAO implementation of amountdeposit and amountwithdrawal, tried for the first time, i can say I'm beginner to this

    @NamedQueries   ({  
    @NamedQuery(name="customers.amountWithdraw", query="update customers set customerBalance = customerBalance - :amount where :customerAccNo"),
    @NamedQuery(name="customers.amountDeposit", query="update customers set customerBalance = customerBalance + :amount where :customerAccNo" )})  

    
    

And here is my DAO implementation

    public Customer amountWithdraw(Customer customer,double amount) {
            customer=(Customer) session.get(Customer.class, customer.getCustomerAccNo());
            if(customer!=null) {
            Query query = session.getNamedQuery("customers.amountWithdraw");
            query.setParameter("customerBalance",customer.getCustomerBalance());        
            query.setParameter("amount", amount );
            query.setParameter("customerAccNo",customer.getCustomerAccNo());
            query.executeUpdate();
            customer=getCustomerByAccNo(customer.getCustomerAccNo());
            return customer;
            }
            return null;
        }
    
        public Customer amountDeposit(Customer customer, double amount) {   
            customer=(Customer) session.get(Customer.class, customer.getCustomerAccNo());
            if(customer!=null) {
            Query query = session.getNamedQuery("customers.amountDeposit"); 
            query.setParameter("customerBalance",customer.getCustomerBalance());
            query.setParameter("amount", amount );
            query.setParameter("customerAccNo",customer.getCustomerAccNo());
            query.executeUpdate();
            customer=getCustomerByAccNo(customer.getCustomerAccNo());       
            return customer;
            }
            return null;        
        }
Rajeev Sreedharan
  • 1,753
  • 4
  • 20
  • 30

1 Answers1

0

Obviously where :customerAccNo is not a valid predicate. You have to compare that parameter to some column/field with an operator e.g. = the equal operator, for this to become a proper predicate. Use this:

@NamedQueries   ({  
    @NamedQuery(name="customers.amountWithdraw", query="update customers set customerBalance = customerBalance - :amount where customerAccNo = :customerAccNo"),
    @NamedQuery(name="customers.amountDeposit", query="update customers set customerBalance = customerBalance + :amount where customerAccNo = :customerAccNo" )})  

Christian Beikov
  • 15,141
  • 2
  • 32
  • 58