Page 1 of 1

About Question enthuware.oce-jpad.v6.2.476 :

Posted: Sat Dec 24, 2016 3:23 pm
by johnlong
The right way would be: TypedQuery<Employee> q = em.createQuery(c);
I think it would be good to mention that in this case "c" has to be typed as well.

Question :
The cast for the return value is not really required (but is not wrong). The following will work as well: List<Employee> returnValue = q.getResultList();
Would it work if CriteriaQuery, Root and TypedQuery are not typed?

Re: About Question enthuware.oce-jpad.v6.2.476 :

Posted: Sun Dec 25, 2016 12:41 pm
by admin
No, I don't think so but you would have to try it out.

Re: About Question enthuware.oce-jpad.v6.2.476 :

Posted: Sun Nov 29, 2020 9:21 am
by johnlong
(Note that em.createQuery always returns a TypedQuery (which extends Query) object when you pass a CriteriaQuery. But when you pass a String, it returns a Query object.)

Not exactly correct.
There is an overloaded method em.createQuery(String s, Class<T> c) which returns TypedQuery<T>

Re: About Question enthuware.oce-jpad.v6.2.476 :

Posted: Mon Nov 30, 2020 3:06 am
by admin
Which part is not correct?
1. em.createQuery always returns a TypedQuery (which extends Query) object when you pass a CriteriaQuery.
This is correct.
2. But when you pass a String, it returns a Query object.)
This is also correct because 1. TypedQuery is a Query 2. In your example, you are not passing just a String. You are passing String and the type.