how to get only value from list my list return key value pair in hibernate native query

Dhruv Rajkotiya :

I am trying to get the total sum of two columns multiplication.

Here is my code:

@Override
public List findTotalAmount(Integer cust_id) {
    // TODO Auto-generated method stub
    SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(
            "SELECT SUM(itm.offerprice*crt.quantity) AS Total_Bill FROM cart crt INNER JOIN item itm ON crt.item_id = itm.item_id where crt.cust_id = "
                    + cust_id);
    query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    List a = query.list();
    System.out.println(a.get(0));

    return a;
}

But when I print the list using System.out.println(a.get(0)); it prints {Total_Bill=1900} but I want only 1900. How to print it? Any other way to print only 1900?

Andronicus :

You're receiving the object because you've assigned a result transformer to map it to the entity by the column name. Simply remove the following line:

query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=18565&siteId=1