I'm executing the following SQL in JPA 2.0 that retrieves the row number of a given row.
SELECT
rownum
FROM
(SELECT
@rownum:=@rownum+1 AS rownum,
tbl.zone_id
FROM
zone_table tbl,
(SELECT
@rownum:=0)t
ORDER BY
tbl.zone_id DESC)t
WHERE
zone_id=?
I'm using the following method in JPA to execute this native SQL query.
Object object = entityManager.createNativeQuery("aboveQuery")
.setParameter("zone_id", id).getSingleResult();
object.toString()
returns like
10.0
11.0
12.0
13.0
and so on based on the id
supplied. So, this value can't be parsed to java.lang.Long
. I expect it to display a value without a decimal point. Why does this query produce this result. It is more related to MySQL rather than JPA.
I'm using MySQL 5.6.11
EDIT:
I can't verify what datatype it returns in MySQL, since it returns the result with no decimal point in MySQL (the primary key which is taken into account here has a type of BIGINT
).
When I tried this query in PHP, it also produced the result with no decimal point. So, I may believe it has to do something with JPA.