From: NHibernate J. <mik...@us...> - 2006-10-31 09:47:29
|
[ http://jira.nhibernate.org/browse/NH-779?page=comments#action_14252 ] Hace commented on NH-779: ------------------------- One extra note: When an abstract class and (one or more) joined-subclasses are not in one mapping file, but joined-subclasses are in separate mappingfiles AND THE MAPPINGFILE WITH THE JOINEDSUBCLASS IS IN A DIFFERENT ASSEMBLY, the connection between the abstract class and the joined subclasses is lost. When trying to read the concreteclassB from NHibernate in code, an error of 'cannot instantiate abstract class' occurs. While when reading ConcreteClassA as an abstractclass, it works perfectly. So it seems 'adding' concreteclassB as an extension for abstractclass in a separate mapping file which is in another assembly seems to be the problem. Hope this helps, > abstract class not recognized using multiple mapping files > ---------------------------------------------------------- > > Key: NH-779 > URL: http://jira.nhibernate.org/browse/NH-779 > Project: NHibernate > Type: Bug > Versions: 1.0.2 > Reporter: Hace > Attachments: JoinedSubClass.zip > > When an abstract class and (one or more) joined-subclasses are not in one mapping file, but joined-subclasses are in separate mappingfiles, the connection between the abstract class and the joined subclasses is lost. An error of 'cannot instantiate abstract class' occurs. > [ AbstractClass.hbm.xml ] > <hibernate-mapping> > <class name="Namespace.Common.AbstractClass, Namespace.Common" table="GeneralItem"> > <id name="GeneralItemId" type="Int32" column="GeneralItemId" > > <generator class="identity"/> > </id> > <property name="GeneralText" column="GeneralText" /> > > <joined-subclass name="Namespace.Common.A.ConcreteClassA, Namespace.Common.A" table="ItemsA" extends="Namespace.Common.AbstractClass, Namespace.Common"> > <key column="GeneralItemId" /> > ..concrete properties for A.. > </joined-subclass> > > </class> > </hibernate-mapping> > [ ConcreteClassB.hbm.xml ] > <hibernate-mapping> > <joined-subclass name="Namespace.Common.B.ConcreteClassB, Namespace.Common.B" table="ItemsB" extends="Namespace.Common.AbstractClass, Namespace.Common"> > <key column="GeneralItemId" /> > ..concrete properties for B.. > </joined-subclass> > </hibernate-mapping> > Items for ConcreteClassB will not be loaded correctly, only because the joined-subclass is not in the SAME mappingfile as ConcreteClassA ? > [ Code ] > List<AbstractClass> itemList = new List<AbstractClass>(); > ISession session = OurSession.CurrentSession; > ICriteria NHibernateCriteria = session.CreateCriteria(typeof(AbstractClass)); > NHibernateCriteria.Add(Expression.In("GeneralItemId", generalItemIds.ToArray())); > try > { > IEnumerable<AbstractClass> enumerable = (AbstractClass[])ArrayList.Adapter(NHibernateCriteria.List()).ToArray(typeof(AbstractClass)); > itemList = new List<AbstractClass>(enumerable); > } > catch(Exception exception) > { > ... log exception.. > } > ...... > dostuff > foreach(ConcreteClassA in itemList) > .... > [ /code ] -- 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 |