Queries with nested subqueries either fail or return wrong results
Description
The attached test shows multiple failing queries which have in common that they are all using nested subqueries. I have no idea if the different queries fail because of different bugs or if it's all because of the same, but I hope they are clear enough that they can be fixed.
Following is an explanation of the test:
Domain model: FirstLevel has a set of components of type SecondLevelComponent. SecondLevelComponent has a many-to-one to ThirdLevel. ThirdLevel is the abstract base of SpecificThirdLevel (table-per-subclass mapping). SpecificThirdLevel has a set of entities of type FourthLevel.
The queries and why they are failing:
_1_Querying_BasedOnFourthLevelExistence_WithIsAndCasting_ShouldReturnSameEntitiesAsLinqToObjects + Should select all FirstLevel entities that have at least one FourthLevel entity as child, implemented by using the "is" operator and then casting the ThirdLevel to a SpecificThirdLevel.
Returns wrong results, the generated SQL checks for existing ThirdLevel childs instead of FourthLevel childs.
_2_Querying_BasedOnFourthLevelExistence_WithSelectAndOfType_ShouldReturnSameEntitiesAsLinqToObjects + Should select same as first query, but this time implemented by using the Select() and OfType() methods.
Fails with exception "QueryException : could not resolve property: class of: component[ThirdLevel,SpecificThirdLevel,SomeBool]". I think it should check the class of ThirdLevel instead of SecondLevelComponent.
_3_Querying_BasedOnFourthLevelProperty_WithIsAndCasting_ShouldReturnSameEntitiesAsLinqToObjects + Should select all FirstLevel entities that have at least one FourthLevel entity with a specific property as child. Implemented with "is" and casting like the first query.
Fails with exception "QueryException : could not resolve property: SomeString of: ThirdLevel". It should search the "SomeString" property on FourthLevel instead of ThirdLevel.
_4_Querying_BasedOnFourthLevelProperty_WithSelectAndOfType_ShouldReturnSameEntitiesAsLinqToObjects + Should select same as third query, but this time implemented with Select() and OfType() like the second query.
Fails with same exception as the second query.
The last two queries are not using a polymorphistic association. Instead they are using the property SecondLevelComponent.SpecificThirdLevel so that no type checking or casting is needed. But they are still failing:
_5_Querying_BasedOnFourthLevelExistence_ByUsingSpecificThirdLevelProperty_ShouldReturnSameEntitiesAsLinqToObjects + Should select same as first and second query.
Returns no entities. But I'm not sure why it doesn't return anything.
_6_Querying_BasedOnFourthLevelProperty_ByUsingSpecificThirdLevelProperty_ShouldReturnSameEntitiesAsLinqToObjects + Should select same as third and fourth query.
Also returns no entities and I also don't know why.
Environment
None
Attachments
1
Activity
Show:
cremor
June 20, 2011 at 12:58 AM
Ups, sorry about the mapping error in query 5 and 6. That's the result of using Fluent NHibernate usually and XML only for NHibernate bugs
About the lists: I know that they behave differently as sets (for transient entities) but other than that it shoudn't cause any problems, right?
Fabio Maulo
June 19, 2011 at 2:49 PM
Tests committed
Fabio Maulo
June 19, 2011 at 2:36 PM
For the others we have to check. btw... you can't map a List<T> to a <set>
The attached test shows multiple failing queries which have in common that they are all using nested subqueries. I have no idea if the different queries fail because of different bugs or if it's all because of the same, but I hope they are clear enough that they can be fixed.
Following is an explanation of the test:
Domain model:
FirstLevel has a set of components of type SecondLevelComponent.
SecondLevelComponent has a many-to-one to ThirdLevel.
ThirdLevel is the abstract base of SpecificThirdLevel (table-per-subclass mapping).
SpecificThirdLevel has a set of entities of type FourthLevel.
The queries and why they are failing:
_1_Querying_BasedOnFourthLevelExistence_WithIsAndCasting_ShouldReturnSameEntitiesAsLinqToObjects
+ Should select all FirstLevel entities that have at least one FourthLevel entity as child, implemented by using the "is" operator and then casting the ThirdLevel to a SpecificThirdLevel.
Returns wrong results, the generated SQL checks for existing ThirdLevel childs instead of FourthLevel childs.
_2_Querying_BasedOnFourthLevelExistence_WithSelectAndOfType_ShouldReturnSameEntitiesAsLinqToObjects
+ Should select same as first query, but this time implemented by using the Select() and OfType() methods.
Fails with exception "QueryException : could not resolve property: class of: component[ThirdLevel,SpecificThirdLevel,SomeBool]". I think it should check the class of ThirdLevel instead of SecondLevelComponent.
_3_Querying_BasedOnFourthLevelProperty_WithIsAndCasting_ShouldReturnSameEntitiesAsLinqToObjects
+ Should select all FirstLevel entities that have at least one FourthLevel entity with a specific property as child. Implemented with "is" and casting like the first query.
Fails with exception "QueryException : could not resolve property: SomeString of: ThirdLevel". It should search the "SomeString" property on FourthLevel instead of ThirdLevel.
_4_Querying_BasedOnFourthLevelProperty_WithSelectAndOfType_ShouldReturnSameEntitiesAsLinqToObjects
+ Should select same as third query, but this time implemented with Select() and OfType() like the second query.
Fails with same exception as the second query.
The last two queries are not using a polymorphistic association. Instead they are using the property SecondLevelComponent.SpecificThirdLevel so that no type checking or casting is needed. But they are still failing:
_5_Querying_BasedOnFourthLevelExistence_ByUsingSpecificThirdLevelProperty_ShouldReturnSameEntitiesAsLinqToObjects
+ Should select same as first and second query.
Returns no entities. But I'm not sure why it doesn't return anything.
_6_Querying_BasedOnFourthLevelProperty_ByUsingSpecificThirdLevelProperty_ShouldReturnSameEntitiesAsLinqToObjects
+ Should select same as third and fourth query.
Also returns no entities and I also don't know why.