-->
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.  [ 5 posts ] 
Author Message
 Post subject: Loading Multiple Objects of the Same [Base] Type
PostPosted: Wed Nov 16, 2005 3:00 pm 
I have a question regarding inheritance and object loading. Here's an abstract example:

class Person;
class Employee : Person;
class Manager : Employee
class SalesPerson : Employee

This would be mapped using the joined-subclass strategy such that all data common to all Person types is stored in the Person table and "table inheritence" is used for each Person type-specific data.

Now, here's my question: say I have the following mapped object:
Code:
class LineOfBusiness {

     public IList Managers {
          get;
          set;
     }

     public IList Employees {
          get;
          set;
     }

     public IList SalesPeople{
          get;
          set;
     }

}


(Essentially, a LineOfBusines would have Employees doing the work, Managers managing the Employees, and SalesPeople that are assigned to "sell, sell, sell" the services of the LineOfBusiness...)

When I try this, I get an error when a Person object is loaded that is both a SalesPerson and a Manager, when using Session.Load(typeof(LineOfBusiness), someId).

Is this possible with NHibernate? I realize that my "LineOfBusiness" example isn't that great and I can try to elaborate on it if need be.

Thanks for any suggestions.


Top
  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 3:03 pm 
As a collegue of mine pointed out, the error doesn't occur until the Lists are actually loaded, in the case when lazy="true" for those one-to-many relationships...

Thanks again.


Top
  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 11:53 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
IMO, if a Person can be a SalesPerson and a Manager; then you should change your inheritance model...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 4:50 pm 
Thanks for you're reply. Since it's easier to ask for forgiveness than permission, here's my actual problem:

Code:
class Report {

     public IList DisplayColumns;

     public IList FilterColumns;

     public IList SortColumns;
}

class BaseColumn;

class DisplayColumn : BaseColumn;

class FilterColumn : BaseColumn;

class SortColumn : BaseColumn;



On a report, a column can be any combination Display, Filter, and Sort Column types. However, when I try Session.Load(typeof(Report), reportId) and load the lists, if a DisplayColumn is also a FilterColumn I get the NHibernate error I previously described.

Granted, this may be a bad design and, if that's the case, I'm open to suggestions. However, can this be handled in NHiberate? Also, is there a test case in the source that I could look at for more information or take as an example?

Thanks so much.

H


Top
  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 6:42 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
I see several options here:
- don't map BaseColumn class at all, pretend it doesn't exist
- use composition instead of inheritance, that is, use only one big class instead of the three subclasses.

As it is now, the hierarchy doesn't make much sense since if BaseColumn is an entity, there can only be one BaseColumn with a given id by definition (identifiers are used to uniquely identify an object/entity/database record, after all).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.