What if I have a query that gets called multiple times in a single thread, and I just want to cache that query (and its result) for that thread (or for that session since I'm using one session per thread), how can I do that ?
Note: My 2nd level cache is turned on but it's used mostly for session.get(...). But I do not want to use it for my query cache because I only need it to live for the duration of my thread ( / session ).
Thanks
I don't know of any such feature for Hibernate.
But this seem to be a very limited and manageable context. I would try to do that is the code. Various ways seem possible at first sight:
Suppose the opposite, that your code is a real mess, and you can't pass a context around. You could have a ThreadLocal variable that contains the result. If not set inside the current thread, call it and store it. Otherwise, just retrieve it.
Between these opposites, solutions are possible, one of them is probably better than others...