java - Classcast Exception while running Projection count query in hibernate -


i using hibernate 4.3.1 final version of hibernate. in hibernate mapping file have defined property integer. eg: <property name= "jobno" type="integer">

database used db2. in jobno column defined integer. when trying retrive count of jobno using projection api as:

criteria.setprojection(projections.count(jobno)); criteria.uniqueresult(); 

it returning long. ideally, should returned integer.

i new can me on?

it returning long. ideally, should returned integer.

you have not hand on it. it's handled jpa implementation (hibernate here).

if know value returned count cannot exceed integer max value (2147483647), should not problem. can convert long integer. if have doubt, can check long value doesn't exceed integer max value.
anyway, advise cast number rather long, may avoid surprise if change jpa implementation.

int jobno = ((number)criteria.uniqueresult()).intvalue(); 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -