-->
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: Inheritance and Many-to-Many relationship
PostPosted: Tue Jul 25, 2006 12:19 am 
Newbie

Joined: Tue Jul 25, 2006 12:03 am
Posts: 3
Hello,

I've been playing around with NHibernate for the past couple days.
I was able to solve most of the problem by looking at the documentation or forum, but I just got one question which I cannot seem to find the answer.

I have 3 tables say tbl_A, tbl_B, and tbl_C.

tbl_A is the base class providing things like first name, last name, email, and so on.
tbl_B extends tbl_A with additional fields (The ID of tbl_B is the ID of tbl_A).
For this inheritance, i used joined-subclass and it was fairly easy.

However, I am stuck with tbl_C.
tbl_C is basically a many-to-many relationship of tbl_A and tbl_B.

To make it more clear, think tbl_A contains all possible users.
tbl_B is sorta like a department leaders which manages multiple group leaders (users in tbl_C).
Each group leader can belong to multiple department leaders (users in tbl_B).

So tbl_C and tbl_B has many-to-many relationship.

I want to make it so that tbl_C still extends tbl_A, but have a collection of users in tbl_B.

in C# it would be something similar to

Code:
public class C : A
{
    private IList _parentLeaders = new ArrayList();

    public IList ParentLeaders
    {
        get { return this._parentLeaders; }
    }

    private C() : A()
    {}
}


something similar to that.

This is what I have for tbl_A and tbl_B.

Code:
<class name="User" table="tbl_A">
    <id name="UID" column="UID" unsaved-value="0">
      <generator class="identity" />
    </id>

    <property name="FirstName" column="FirstName" />
    <property name="LastName" column="LastName" />
    <property name="Email" column="Email" />
    <property name="UserName" column="UserName" />

    <joined-subclass name="DepartmentUser" table="tbl_B">
      <key column="UID" />
      <property name="SomeOtherProperty" column="SomeOtherProperty" />
    </joined-subclass>
  </class>


(Modified the class name and etc, so there might be mistakes in here, but for the actual code, it works.)

tbl_C has UID, UserUID (which is in tbl_A) and DepartmentUserUID (which is in tbl_B)

I tried to use <key column="UserUID" />, but it returns WrongClassException or something similar to that.

tbl_C is not exactly ISA tbl_A, but i was wondering if there is any way to group the UserUID in tbl_C and return the collection of tbl_B users?

Any help will be appreciated.

Thanks!
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 26, 2006 5:17 am 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
You should think in objects not in tables!

So you have objA mapped to tblA and objB which inherits from objA and is mapped on 2 tables: tblA and tblB

As you can't work with part of objects you will understand that you can't have a many-to-many relationship between tblA and tblB. In fact the many-to-many relationship is between tblA and the same tblA (but only the rows which have corresponding entries in tblB).

HTH,
Radu


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.