clean up Query APIs #4454
Replies: 4 comments 4 replies
-
Many of these come from JPA contracts which we just covariantly override.
I agree that passing a
+1
+1
Not sure which "wildcards" you mean here. Could you elaborate?
This problem stems from the fact that
This should work already. If not, that would be a bug IMO.
I guess that would return a
Like stated above, the raw type issue comes from the fact that we don't have a pendant for |
Beta Was this translation helpful? Give feedback.
-
See work-in-progress here: #4516 |
Beta Was this translation helpful? Give feedback.
-
These problems are partially alleviated by #4516. |
Beta Was this translation helpful? Give feedback.
-
This cleanup was done in H6. |
Beta Was this translation helpful? Give feedback.
-
In parallel with thinking about this idea, I've also been thinking about options for cleaning up the
Query
API as it exists today. I'm concerned about a number of things.Accumulated cruft on the
Query
interfaceQuery
now has ~42 different methods for binding parameters. The main offender seems to be date/time related methods. A couple, likewere maybe once useful back in the day, but aren't relevant anymore.
Some of the others don't look to me like they could have ever been useful, for example, about 8 methods like:
where I can't imagine why you would ever need to pass the
TemporalType
explicitly for ajava.time
type.That is to say, we seem to have 8 methods on
Query
to support the important usecause of people abusingDateTime
s to represent dates. That doesn't seem right at all.Furthermore, we have both
list()
andgetResultList()
, anduniqueResult()
andgetSingleResult()
, along with thescroll()
methods andResultTransformer
stuff that probably aren't useful.Let's consider deprecating some of these operations, with an eye to eventually removing them.
Too many ways to get a named query
QueryProducer
defines competingcreateNamedQuery()
andgetNamedQuery()
operations, along withgetNamedNativeQuery()
methods which don't especially look useful to me. This stuff is just fallout from the introduction of JPA, which happened 15 years ago.If, as I suppose, some of these methods are redundant, let's deprecate them.
Issues with raw types
My biggest problem, however, is that it's too easy to get a raw
Query
. The versions ofcreateQuery()
which take just a string all return raw types, which results in at least one compiler warning on the user side. Sometimes you get even more warnings when you call methods with generic parameter types or wildcards. This is much more of a problem withNativeQuery
than withQuery
, especially withNativeQuery.addEntity()
.This problem is not fixable (I tried really hard) due to the way
Session
inheritsEntityManager
. I would love to be able to declarecreateQuery()
as:but that's just not possible.
Now, in principle this isn't so bad, I suppose, since you can call the version of
createQuery()
that accepts a class. It's your own fault that you used the untyped version! What are you even complaining about? Well, yeah, except that:createQuery()
doesn't let me passObject[].class
as an argument (this might just be a bug),createQuery(CriteriaDelete)
andcreateQuery(CriteriaUpdate)
always return a raw type, andcreateNativeQuery()
that accepts a resultsetmapping and a class.So in at least those cases I'm SOL.
My proposed actions here are:
Query
andNativeQuery
(I've already done this on a branch),createQuery(CriteriaDelete)
andcreateQuery(CriteriaUpdate)
returnQuery<Void>
orQuery<Object>
,Object[].class
as an argument (and checkjakarta.persistence.Tuple
, I don't recall if that works or not),createNativeQuery(String,String,Class)
, andcreateQuery()
methods that return a raw type.Beta Was this translation helpful? Give feedback.
All reactions