This content has been marked as final. Show 2 replies
INHERITANCE_OUTER_JOIN affects all queries to that entity tree. This would affect mappings where the type is the A superclass, but in the database be of type B or C, returning null since there is no A for that reference. Can you provide the mapping and what gets returned when INHERITANCE_OUTER_JOIN isn't set?
"Set QueryHints.INHERITANCE_OUTER_JOIN to false" and "set InheritancePolicy().setShouldReadSubclasses() to false" have different effects.
"Set QueryHints.INHERITANCE_OUTER_JOIN to false" - which is default - will issue separate query for each subclass:
"set InheritancePolicy().setShouldReadSubclasses() to false" only returns the root class instances which match the search criteria:
In my test case, Director extends Manager which extends Employee, Employee has a relationship to Dog.
In the database, there are one instance of Director, Manager and Employee, all three of them have id set to 'Bob', and all have a related Dog instance.
The I query with "SELECT o FROM Employee o WHERE o.id = 'Bob'"
With QueryHints.INHERITANCE_OUTER_JOIN set to false, I saw three queries issued against Director, Manager and Employee tables, and returned 3 instances of 'Bob' as expected, and navigating to Employee.getDog() returned the Dog instance correctly.
With InheritancePolicy().setShouldReadSubclasses() set to false, there is one query issued against the Employee table and returned one Employee instance only, and navigating to Employee.getDog() returns the Dog instance correctly.
So if your intention is to bring back the root class instances only, then "set InheritancePolicy().setShouldReadSubclasses() to false" should work for you.
Or are you trying to bring back all three instances as Employee without the subclasses' attributes and relationships being populated?