Issue
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
...
@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
.
Solution
Use:
((Long) userService.getAttendanceList(currentUser)).intValue();
instead.
The .intValue()
method is defined in class Number
, which Long
extends.
Answered By - fge
Answer Checked By - Marilyn (JavaFixing Volunteer)