1

I have a SQL projection query that returns a list, but I want a single result. Here is my projection query:

Criteria criteria = getCurrentSession().createCriteria(TbLoyaltytrans.class) .add(Restrictions.eq("custid", custId)) .setProjection(Projections.projectionList() .add(Projections.sum("pointin").as("pointin")) .add(Projections.sum("pointout").as("pointout")) .add(Projections.sqlProjection( "(pointin - pointout) as points", new String[]{"points"}, new org.hibernate.type.DoubleType[]{ new org.hibernate.type.DoubleType() }), "points") ); 

I want a single object, i.e.: the count from the above query.

What I did wrong with the above query?

0

1 Answer 1

1

I assume your are using criteria.list() in order to get the list. You can use criteria.uniqueResult() and it will return a single Object or null.

Sign up to request clarification or add additional context in comments.

2 Comments

i got the ans i just return (Object[]) criteria.uniqueResult() and iterate this as i understand by using projection you will get three results as output in above query 1st if for Projections.sum("pointin").as("pointin") sencond is for Projections.sum("pointout").as("pointout")) and the last one is your SQLprojection output that i want i iterate this array and fetch third position like Double reedeemPoints =new Double(obj[2].toString()) and it works for me thank you for your ans
If it really worked to you, your could accept his answer. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.