From: Andrei A. (JIRA) <nh...@gm...> - 2011-05-16 15:59:46
|
[ http://216.121.112.228/browse/NH-2705?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21097#action_21097 ] Andrei Alecu commented on NH-2705: ---------------------------------- Thanks Fabio. I understand the considerations, but I think I took the necessary precautions (only having Id in the many-to-one subclass, separate subclasses, etc), and it seems to work in our application otherwise, except for this fetch issue. I'm mostly just interested in NHibernate being able to ignore the Fetch on component, so I can have repository methods that can take either subclass and not throw an invalid join exception. Less concerned about the invalid SQL right now. > 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: Improvement > Components: Core > Affects Versions: 3.1.0 > Reporter: Andrei Alecu > Priority: Minor > Attachments: nh2705 test.patch > > > 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 |