A criteria query with a filter (to the elements of a one-to-many relation) can initialize the persistent set with so that it returns not all items.
More detailed description:
1a. Person bean is a simple entity
1b. Person bean has multiple Dog beans
2. Query Person bean with a filter to Dog
3a. The returns good result in the terms of Person
3b. The set of returned Person beans (which contains Dog instances) does not contains every referenced Dog item
4. After querying Person beans again with session.get() the returned Person instances still does not have the full set (with every Dog reference)
1. The Set of Person instances should contain every referenced Dog bean. (I know it cannot be done with one query in general case)
2. If I query the same items with session.get() it shouldn't be affected by previous query and its set should contain every item. (I think this is the most serious problem)
3. The PersistentSet shouldn't marked with initialized=true, if its content can not be guaranteed that it contains every item.
The set of the same query is different (and contains every item), if its PersistentSet is initialized in the same session by an other query. (e.g. with a previous session.get().toString())
For more detailed description please check the test case. PersistentSetTest.zip
Run mvn install or the test cases on class test.PeopleWithDogsTest.
Hibernate 5.0.3, 4.1.2 and 3.5.5
java version "1.8.0_60" and java version "1.6.0_31"
Same problem for us... please, anyone have a solution ?
This bug report does not indicate that the reported issue affects version 5.x. Versions prior to 5.x are no longer maintained. It would be a great help to the Hibernate team and community for someone to verify that the reported issue still affects version 5.x. If so, please add the 5.x version that you verified with to the list of affected-versions and attach the (preferably SSCCE) test case you used to do the verification to the report; from there the issues will be looked at during our triage meetings.
For details, see http://in.relation.to/2015/10/27/great-jira-cleanup-2015/
As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.
The problem is still reproducible with Hibernate 5.0.3-Final. I attached the PersistentSetTest.zip with updated tests and I have updated the description.