I saw the links but i can't figure it out.. my collection has to be only in one subclass (due to domain) and it can contains either nodes either leaves if i use a strongly typed one i have to use a collection for each concrete type and i'd like to use only one collection.. am i wrong ?
thanks On 16 Feb, 18:42, Fabio Maulo <[email protected]> wrote: > hmmm... I saw this matter in some other place...The Childen collection is > strongly typed ? > If yes with which class ? > You should use a base generic interface as INode<T> and map the collection > on each subclass, instead the base class, using the <where> tag. > > BTW here is the example > ;)http://fabiomaulo.blogspot.com/2008/10/entity-name-in-action-strongly... > > and this other using > table-per-class-hierancyhttp://fabiomaulo.blogspot.com/2008/10/power-of-orm.html > > That example is not exactly the same but it solve a very similar problem > > 2009/2/16 [email protected] <[email protected]> > > > > > > > Hi all, > > > in my domain model i have a base abstract class called NodeBase and 2 > > concrete class Node and Leaf. > > The only particular thing is that class Node has a collection of > > NodeBase (this is a composite modeling a tree). > > i've mapped all with nhibernate and here is the hbm.xml file: > > > <class name="NodeBase" table="TreeNodes"> > > <id name="NodeId"> > > <generator class="assigned"/> > > </id> > > > <discriminator column="NodeOrLeaf"/> > > <property name="NodeName" not-null="true"/> > > <property name="ParentNodeId" not-null="true"/> > > <property name="NodeType" not-null="true"/> > > > <subclass name="Node" discriminator-value="N"> > > <bag name="Children" lazy="false" cascade="all-delete-orphan"> > > <key column="ParentNodeId"/> > > <one-to-many class="NodeBase"/> > > </bag> > > <!-- some properties --> > > </subclass> > > > <subclass name="Leaf" discriminator-value="L"> > > <!-- some properties --> > > </subclass> > > </class> > > > now, the point is: > > > i would like to save and load data to/from the db by doing save/load > > only on the root node of the tree. > > by now, saving is working correctly (i instantiate a root node with > > some chilld (nodes or leaves or both) and for each child node (only > > node) i can add other nodes, leaves etc..) , i mean, i do save on the > > root node and the entire tree is stored in the db. > > > the problem is on load. when i try to load a node (the root node) > > hibernate tries to load the Children collection and it takes the first > > element (e.g. a Leaf, so discriminator='L') and throws an exception > > saying that the element (whose discriminator is L) is not a NodeBase > > as said in the mapping file. > > my thought is: leaf and node are subclasses of nodebase so aren't also > > a nodebase ? > > > any help ? > > > hope i was clear > > > thanks so much > > > cheers > > > Alex > > -- > Fabio Maulo --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
