sql - java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long -


i want return number of rows using native sql. console says me java.math.biginteger cannot cast java.lang.long. what's wrong? method:

public long getnumrows(integer id){          session session = null;          session = this.sessionfactory.getcurrentsession();         query query = session                 .createsqlquery("select count(*) controllnews news_id="                         + id + ";");         list firstresult = query.list();          return (long) firstresult.get(0);       } 

use biginteger#longvalue() method, instead of casting long:

return firstresult.get(0).longvalue(); 

seems firstresult.get(0) returns object. 1 option typecast biginteger:

return ((biginteger)firstresult.get(0)).longvalue(); 

but don't this. instead use way provided nambari in comments. i'm no user of hibernate, can't provide hibernate specific solution.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -