java - how to fetch last column of the selected table using hibernate? -
i trying fetch id of last column in descending order.
the query returns last column
select id from(select id challan order id desc) rownum=1;
now trying same thing using hibernate.
public long getidonchallantable() { session = sessionfactory.opensession(); trans = session.begintransaction(); query<object[]> query = session.createnativequery("select id from(select id challan order id desc) rownum=1;"); long value = 0l; list<object[]> list = query.getresultlist(); ( object lst : list){ object[] objects =(object[]) lst; value=(long)(objects[0]); } return value; }
and error is:
2017-07-26 12:37:36 [http-nio-7080-exec-1] warn :: sql error: 911, sqlstate: 22019 2017-07-26 12:37:36 [http-nio-7080-exec-1] error:: ora-00911: invalid character update error javax.persistence.persistenceexception: org.hibernate.exception.sqlgrammarexception: not extract resultset
you don't need semicolon @ end of query , please use proper whitespacing. in clause, don't have whitespace between subquery , keyword.
note: don't forget commit/rollback transaction @ end , handle exceptions well. hope sketch show problem , not code real world application.
Comments
Post a Comment