[hibernate-dev] EntityGraph query spaces not applied to Query (HHH-11213)
Gail Badner
gbadner at redhat.com
Tue Dec 20 04:47:11 EST 2016
See below...
On Fri, Dec 16, 2016 at 5:03 PM, Steve Ebersole <steve at hibernate.org> wrote:
> It likely is not an issue. Query spaces only come into play with regards to
> restrictions. Since the EntityGraph is not part of the query proper
> restrictions cannot be based on it.
>
> That would be a scenario to try though... create a query restricting results
> based on some joined attribute and then supply an EntityGraph hint for that
> attribute. But IMO that is a completely contrived scenario.
I've confirmed that adding the restriction on an attribute to the
Query will add that joined entity as an affected query space, with or
without an EntityGraph. Any changes affecting the joined query space
would force a flush before executing the query.
For example, changing the query in the PR to something like:
query = entityManager.createQuery( "from Company.class where
location.address = '123 somewhereelse'");
query.setHint( QueryHints.HINT_LOADGRAPH, entityGraph );
The change to location#address that is already in the Session would
result in flushing the session before executing the query.
Is this the sort of test that you are suggesting? If not, please give
me an example.
>
> On Fri, Dec 16, 2016, 6:09 PM Gail Badner <gbadner at redhat.com> wrote:
>>
>> Query spaces for EntityGraph nodes/subgraphs are not currently added
>> when applied to a Query, and so the session is not flushed if it
>> contains updated data relevant to the EntityGraph that is not in the
>> query spaces defined for the Query.
>>
>> I originally though this was a critical issue, but now that I'm
>> looking into it, I'm not so sure. I am having a hard time coming up
>> with a test case where it matters.
>>
>> I've created a pull request with the test case attached to HHH-11213,
>> with some added checks to detect if the session flushes. [1]
>>
>> In this case, the session does not flush, but the query results are
>> still correct because the updated entity is taken from the Session,
>> not from the ResultSet returned by the query.
>>
>> I wonder now if it really is necessary to flush the Session when the
>> session has updates that apply *only* to the EntityGraph (and not to
>> the base Query).
>>
>> Thoughts?
>>
>> Thanks,
>> Gail
>>
>>
>> [1] https://github.com/hibernate/hibernate-orm/pull/1707
>> _______________________________________________
>> hibernate-dev mailing list
>> hibernate-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/hibernate-dev
More information about the hibernate-dev
mailing list