|
From: Andrei A. (JIRA) <nh...@gm...> - 2011-05-14 13:20:40
|
Linq/Hql/Criteria Fetch on class hierarchy generates invalid SQL when derivees mix component and many-to-one mappings
---------------------------------------------------------------------------------------------------------------------
Key: NH-2705
URL: http://216.121.112.228/browse/NH-2705
Project: NHibernate
Issue Type: Bug
Components: Core
Affects Versions: 3.1.0
Reporter: Andrei Alecu
Priority: Major
Consider the following scenario:
public class ItemBase
{
public virtual int Id { get; set; }
public virtual SubItemBase SubItem { get; set; }
}
public class ItemWithComponentSubItem:ItemBase { }
public class ItemWithManyToOneSubItem:ItemBase { }
ItemWithComponentSubItem defines in its mapping that SubItem is a component of SubItemComponent type (which derives from SubItemBase)
ItemWithManyToOneSubItem defines in its mapping that SubItem is a many-to-one of SubItemEntity type (again, derives from SubItemBase)
Running the following query with fetch results in invalid SQL being executed:
from ItemBase i left join fetch i.SubItem
Removing the fetch makes it work properly.
from ItemBase i
Also, this works:
from ItemWithManyToOneSubItem i left join fetch i.SubItem
But this doesn't:
from ItemWithComponentSubItem i left join fetch i.SubItem (one would argue there's nothing to fetch here, but instead of throwing an exception, the fetch instruction should just be ignored and maybe a warning logged, it would allow for much better reuse of code)
I will attach a unit test that demonstrates this bug, and also a related one at NH-2615.
I believe the correct behavior here is to allow fetch on components, and simply ignore it rather than throwing an exception.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://216.121.112.228/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
|