I have a request like this
SET @rownum := 0; SELECT rank, id, point FROM ( SELECT @rownum := @rownum + 1 AS rank, id, point FROM user ORDER BY point DESC ) AS result WHERE id = 0;
Therefore, I use EntityManager#createNativeQuery to execute this query.
Object temp = em.createNativeQuery(sql).getSingleResult();
So now the temp object contains information about rank , id and point . Please note: rank not an attribute inside my object, rank calculated when the request is executed â cannot pass this object to my Entity.
So how can I get the rank value?
EDIT
Here is the answer to what I am looking for. Therefore instead
Object temp = em.createNativeQuery(sql).getSingleResult();
Do it
Object[] temp = (Object [])em.createNativeQuery(sql).getSingleResult();
Since I want to know the rank value, I would do it
Long rank = (Long) temp[0];
source share