From: NHibernate J. <mik...@us...> - 2006-12-29 21:45:31
|
[ http://jira.nhibernate.org/browse/NH-826?page=all ] Aaron Jensen updated NH-826: ---------------------------- Attachment: NH826.patch This patch fixes it for me. It's hacky and doesn't feel right, so I'm sure theres a more top down approach to this. Here's my side of a conversation I had with Ayende explaining the issue: (1:30:11 PM) Aaron: it's hacky (1:30:25 PM) Aaron: and i dont know if its the right solution (1:31:05 PM) Aaron: the issue is that the loadelementsfromcolleciton gets the collectionpersisters for all possible collections for an entity (including it's subclasses) (1:31:38 PM) Aaron: so if an entity is of the base class, it creates a collection that belongs to the subclass (1:31:46 PM) Aaron: and it's automatically unreferenced (1:31:49 PM) Aaron: because it can't be referenced (1:32:13 PM) Aaron: ok, let me back up... you have a subclass (1:32:19 PM) Aaron: and you have a base class (1:32:26 PM) Aaron: sub has a collection (1:32:29 PM) Aaron: base does not (1:32:36 PM) Aaron: then you have a container class, that has a collection of base (1:32:48 PM) Aaron: you get a row from the resultset (1:32:56 PM) Aaron: and you've got to hydrate all the collections it contains (1:33:18 PM) Aaron: so, if you get container fetch base fetch collection (1:33:30 PM) Aaron: or just container join base fetch collection (1:34:12 PM) Aaron: so the collection persister for the collection is there, and it's owner is base (1:34:30 PM) Aaron: even though base does not have that collection (1:34:53 PM) Aaron: at some point the entity's type is determined.. and it's instantiated (1:34:59 PM) Aaron: so base is instantiated (1:35:04 PM) Aaron: because that's what it is, it's NOT sub (1:35:34 PM) Aaron: but the collectionpersister for the collection still exists because it doesn't know at the time it's created that it's not needed... AND it's needed later if there is a sub in the container (1:35:55 PM) Aaron: so either the set of collectionpersisters needs to change on each row based on the type (1:36:08 PM) Aaron: or we need to filter using reflection like my patch does (1:37:31 PM) Aaron: no idea how it worked in 1.0 (1:37:34 PM) Aaron: didn't look at the code (1:37:41 PM) Aaron: it may not have (1:37:49 PM) Aaron: because they changed it to fetch as default (1:37:55 PM) Aaron: so we may have never seen it > Using Criteria to query for an item throws on Flush in some situations > ---------------------------------------------------------------------- > > Key: NH-826 > URL: http://jira.nhibernate.org/browse/NH-826 > Project: NHibernate > Type: Bug > Components: Core > Versions: 1.2.0.Beta2 > Reporter: Aaron Jensen > Fix For: 1.2.0.Beta3 > Attachments: NH826.patch, NHibernateTest.zip > > The situation is best described by the attached sample project, but I will attempt to explain in words when this problem occurs. > EntityA has a many-to-many to EntityB > EntityB has a subclass EntityC > EntityC has a one-to-many to EntityD > If you create an EntityB and associate it to EntityA, then query for EntityA via Criteria (but not via HQL) then Session.Flush() will fail with: > NHibernate.HibernateException: You may not dereference an collection with cascade="all-delete-orphan" > at NHibernate.Impl.SessionImpl.UpdateUnreachableCollection(IPersistentCollection coll) in c:\net\nhibernate\nhibernat > e\src\NHibernate\Impl\SessionImpl.cs:line 3957 > at NHibernate.Impl.SessionImpl.FlushCollections() in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\SessionImpl.cs: > line 3802 > at NHibernate.Impl.SessionImpl.FlushEverything() in c:\net\nhibernate\nhibernate\src\NHibernate\Impl\SessionImpl.cs:l > ine 3090 > The collection it is complaining about is a collection of EntityD objects which should never have been created in the first place. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.nhibernate.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |