public Long getId()
{
Some code ...
TypedQuery<Long> query = entityManager.createQuery(sQuery, Long.class);
return query.getSingleResult();
}
From this code i get a ClassCastException
from Integer
to Long
. I checked query.getSingleResult();
in the debugger and i conatined the Integer
5.
If i change the code to query.getSingleResult().longValue();
it still does not work. I get the same Exception. But if i use
Number tmp = query.getSingleResult();
return tmp.longValue();
it works. My Question is Why doesnt the first solution work? Surley i can change my query, but i only want to know why the secound works and the first do not.
Feel free to change the title of my question. Thanks in advance!