redesign query execution #4452
Replies: 3 comments 7 replies
-
It's important to realize that this proposal has exactly zero impact on existing APIs, and comes with no cost in terms of backward-compatibility. At least in the initial implementation, |
Beta Was this translation helpful? Give feedback.
-
So First of all, let's acknowledge that internally, we have a contract called I think the idea of having an immutable query object is interesting, but I think we have to define some expectations. It seems to me that the Let's classify the existing representations we have to understand what this new thing could be.
If I understand correctly from this classification, this |
Beta Was this translation helpful? Give feedback.
-
So, this wasn't a terrible idea, and if we were starting from scratch, I would still consider it. But recent work has gone in a kind of different direction, and some of the issues above have been addressed in other ways. I'm going to close this. |
Beta Was this translation helpful? Give feedback.
-
For almost as long as I remember, I’ve been sort-of unhappy with how
Query
objects work in Hibernate. There’s various sources of my discomfort, but they include:Session
to create one. I can’t just go and call an arbitrary function to make on, nor store one in a static variable.Query
object is mutable, for no especially convincing reason.Session
interface without about a million methods for creating queries of all sorts.EntityManager
to deal with.Tonight it struck me that I’ve been being extremely dense about this, and that the solution has been pretty much staring me in the face all along.
This is perhaps going to look a bit crazy at first, but hear me out:
new
, andFor example:
whether you specify the type using
<Person>
or by passing inPerson.class
us up to you, and a matter of taste, I don’t care. Of course you can still use a raw type if you prefer.A native query would work similarly:
or:
and you can guess what this looks like for criteria queries, or for Max’s favorite tuple stuff.
That’s all fine, I think, but where this really starts to look nice is for something like this:
I think this is an idea worth exploring.
Beta Was this translation helpful? Give feedback.
All reactions