Even I'm casting Object
into int, but this exception occur...
Actually my Hibernate-JPA method was return Object
then I'm converting that Object
into int
...
Here is my Hibernate code:
@Transactional
public Object getAttendanceList(User user){
Query query = entityManager.createQuery("select Count(ad) from AttendanceDemo ad inner join ad.attendee at where at.user=:user",
Long.class);
query.setParameter("user", user);
return query.getSingleResult();
}
Now I'm converting this Object
as int
:
int k = (Integer) userService.getAttendanceList(currentUser);
I'm converting Object
to Integer
.
This question is related to
java
hibernate
object
type-conversion
The number of results can (theoretically) be greater than the range of an integer. I would refactor the code and work with the returned long value instead.
Source: Stackoverflow.com