Closed Quix0r closed 1 year ago
I don't understand this issue. TypedQuery
is the genericized version of Query
. If we added a type parameter to Query
, then we wouldn't need TypedQuery
anymore.
EntityManager
has had this method for a very long time:
<T> TypedQuery<T> createNamedQuery(String name, Class<T> resultClass);
I believe this is all that's needed.
I'm going to close this; if @Quix0r speaks up to explain how this isn't a solution, we can always reopen this.
Okay, so I just have to replace Query
with TypeQuery<User>
and then I can remove the @SuppressWarnings
from the method?
Correct.
Then this ticket needs being marked as invalid
and maybe locked?
This is a copied issue from https://bugs.eclipse.org/bugs/show_bug.cgi?id=522384 I had reported: I hope I'm at the right spot.
The javax.persistence.Query should be enhanced with a generic to avoid dangerous casts. Some methods like getSingleResult() and getResultList() or even more will benefit from it, requiring no casting and no pre-check if the cast may work.
Some current Java code: (I assume here, the field "em" is already properly injected with the entity manager)
New, proposed way: