I'm learning JPA and doing some hands one with JPQL. I am having trouble in CASE expressions. For example, this query,
Query caseQuery = em
.createQuery("SELECT t , CASE WHEN t.salary = 20000 THEN '20k' WHEN t.salary = 40000 THEN '40k' ELSE 'No salary' END FROM Teacher t");
and executing it using
List<Teacher> teachers = (List<Teacher>) caseQuery.getResultList();
but whenever I try to print the results out, I'm getting ClassCastException
that Object
cannot be converted to Teacher
I've tried using TypedQuery
for Teacher
but it didn't work. Could you experts please throw some light on executing this CASE
statements in JPQL?