These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Polymorphic tree with mixed type child collection
PostPosted: Sun Aug 26, 2007 11:35 am 
Newbie

Joined: Sun Aug 26, 2007 11:07 am
Posts: 2
Hi,

I'm working with
Hibernate version: 1.2.0.4000 on .NET 2.0 using MS-SQL-Server 2005.

Implementing a polymorphic tree I got a strange problem with nodes, where the child collection should return mixed subtypes.

The base class is

Code:
public class ProdStructNodeWithChilds
    {
[...]
        private IList<ProdStructNodeWithChilds> childs;
        public virtual IList<ProdStructNodeWithChilds> Childs
        {
            get { return childs; }
            protected set { childs = value; }
        }
[...]       
    }


There are three derived classes doing nothing special in sense of persistence

Code:
    public class Profile : ProdStructNodeWithChilds
    { [...]    }
    public class ProductGroup : ProdStructNodeWithChilds
    { [...]    }
    public class Product : ProdStructNodeWithChilds   
    { [...]    }


This classes are mapped following the one-table-per-hierarchy pattern. The entity table looks like
Code:
CREATE TABLE cc3_OrgStructNode (
    ID int IDENTITY(1,1) NOT NULL,
    Type char(4) NOT NULL,  // Subclassing descriminator
    Name nvarchar(50) NOT NULL,
[...]
      // Some subclass fields                               
[...]
    CONSTRAINT PK_OrgStructNode PRIMARY KEY CLUSTERED ( ID ASC ) "
)


For the relations in the the tree is an additional table

Code:
CREATE TABLE dbo.cc3_OSNParent_2_OSNChild(
    ParentID int NOT NULL,
    ChildID int NOT NULL,
   SortOrder int NOT NULL,
   CONSTRAINT PK_cc3_OSNParent_2_OSNChild PRIMARY KEY CLUSTERED (ParentID ASC, ChildID ASC)
)


The mapping is :

Code:
<class name="ProdStructNodeWithChilds" discriminator-value="PSNC">
        <list
          name="Childs"
          table="cc3_OSNParent_2_OSNChild"
          generic="true">
          <key column="ParentID"/>
          <index column="SortOrder" />
          <many-to-many column="ChildID" class="ProdStructNodeWithChilds"/>
        </list>
        <subclass name="Profile" discriminator-value="Prfl" />
        <subclass name="ProductGroup" discriminator-value="PrGr" />
        <subclass name="Product" discriminator-value="Prod" />
</class>   


All works fine so far, when the relation table only returns elemens of one subtype.
F.E. if a "Profile" node only has "Product"s as childs, the Childs collection will contain the "Product"s as expected. When a "Profile" only has "ProductGroup"s as child, the Childs collection will contain the "ProductGroups"s as expected.

BUT the problem: If there is a mixed set of subtypes in the db relation, f.e. "Product"s and "ProductGroup"s as children of a "Profile", the "Childs" collection only has elements of one of the subtypes after loading the "Profile". In my case such mixed db relation on return "ProductGroup" elements (may be random result).

There is no exception, the log shows nothing special.

Any ideas? How can I accomplish such mixed type child relations?

Thanks in advance for any information.
(Beg your pardon for my poor englisch.)

Regards
Martin


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 26, 2007 12:21 pm 
Newbie

Joined: Sun Aug 26, 2007 11:07 am
Posts: 2
Could get a step further by myself.

Changing the mapping to "<set ... " (removing SortOrder and changing from IList to ICollection in C# sources) I'm getting the complete mixed type collection.

But that's not exactly what I need.
Any way to use the "<list.. >" mapping for such mixed result collections?

Regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.