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)
Expected behavior: 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.
Note: 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}}.
|