-->
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.  [ 4 posts ] 
Author Message
 Post subject: NHibernate.Mapping.Attributes problem with JoinedSubclass
PostPosted: Thu Jun 02, 2005 12:07 pm 
Newbie

Joined: Thu Jun 02, 2005 12:00 pm
Posts: 8
I'm having a little trouble with the NHibernate.Mapping.Attributes in my project with regards to the JoinedSubclass tag. I have two tables, Faculty and User, where Faculty is a joined-subclass of User.

Code:
[JoinedSubclass("Faculty",typeof(User))]
[JoinedSubclassKey("UserID")]
Internal class Faculty : User


Code:
- <class name="edu.depaul.cti.col.DataAccessLayer.DataObjects.User, DataAccessLayer" table="[User]">
- <id name="Id" type="Int32" column="UserID" access="property" unsaved-value="0">
  <generator class="NHibernate.Id.IdentityGenerator, NHibernate" />
  </id>
  <property name="LoginName" column="LoginName" access="property" type="String" />
  <property name="ExpireDate" column="ExpireDate" access="property" type="DateTime" />
  <property name="Password" column="[Password]" access="property" type="String" />
  <property name="Prefix" column="Prefix" access="property" type="String" />
  <property name="FirstName" column="FirstName" access="property" type="String" />
  <property name="MiddleName" column="MiddleName" access="property" type="String" />
  <property name="LastName" column="LastName" access="property" type="String" />
  <property name="Gender" column="Gender" access="property" type="String" />
  <property name="EMail" column="EMail" access="property" type="String" />
  <property name="AlternateEMail" column="UseAlternateEMail" access="property" type="String" />
  <property name="UseAlternateEMail" column="IsAlternateEMail" access="property" type="String" />
  <property name="DataSourceFlag" column="DataSourceFlag" access="property" type="String" />
  <property name="DataSourceReferenceID" column="DataSourceReferenceID" access="property" type="String" />
  <property name="Status" column="Status" access="property" type="String" />
  <property name="CreateTime" column="CreateTime" access="property" type="DateTime" />
  <property name="UpdateTime" column="UpdateTime" access="property" type="DateTime" />
- <set name="CreatedAssignments" table="Assignment" access="property" lazy="true">
  <key column="CreatorID" />
  <one-to-many class="edu.depaul.cti.col.DataAccessLayer.DataObjects.Assignment, DataAccessLayer" />
  </set>
- <!-- edu.depaul.cti.col.DataAccessLayer.DataObjects.Faculty, DataAccessLayer
  -->
- <joined-subclass name="edu.depaul.cti.col.DataAccessLayer.DataObjects.Faculty, DataAccessLayer" table="Faculty">
  <key column="UserID" />
  <property name="Title" column="Title" access="property" type="String" />
  <property name="Office" column="Office" access="property" type="String" />
  <property name="OfficePhone" column="OfficePhone" access="property" type="String" />
  <property name="Homepage" column="Homepage" access="property" type="String" />
  <property name="InforPage" column="InforPage" access="property" type="String" />
  <property name="OtherInfo" column="OtherInfo" access="property" type="String" />
  <property name="LoginName" column="LoginName" access="property" type="String" />
  <property name="ExpireDate" column="ExpireDate" access="property" type="DateTime" />
  <property name="Password" column="[Password]" access="property" type="String" />
  <property name="Prefix" column="Prefix" access="property" type="String" />
  <property name="FirstName" column="FirstName" access="property" type="String" />
  <property name="MiddleName" column="MiddleName" access="property" type="String" />
  <property name="LastName" column="LastName" access="property" type="String" />
  <property name="Gender" column="Gender" access="property" type="String" />
  <property name="EMail" column="EMail" access="property" type="String" />
  <property name="AlternateEMail" column="UseAlternateEMail" access="property" type="String" />
  <property name="UseAlternateEMail" column="IsAlternateEMail" access="property" type="String" />
  <property name="DataSourceFlag" column="DataSourceFlag" access="property" type="String" />
  <property name="DataSourceReferenceID" column="DataSourceReferenceID" access="property" type="String" />
  <property name="Status" column="Status" access="property" type="String" />
  <property name="CreateTime" column="CreateTime" access="property" type="DateTime" />
  <property name="UpdateTime" column="UpdateTime" access="property" type="DateTime" />
- <set name="CreatedAssignments" table="Assignment" access="property" lazy="true">
  <key column="CreatorID" />
  <one-to-many class="edu.depaul.cti.col.DataAccessLayer.DataObjects.Assignment, DataAccessLayer" />
  </set>
  <many-to-one name="School" column="SchoolID" access="property" class="edu.depaul.cti.col.DataAccessLayer.DataObjects.School, DataAccessLayer" />
  </joined-subclass>
  </class>



Now when I dump out the XML mapping that I get when I have this, it thinks that all of the properties in User are also in Faculty (fields that don't exist in Faculty but in User are trying to be mapped distinctly in Faculty), but this isn't what I want. Am I using these tags correctly?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 02, 2005 9:37 pm 
Newbie

Joined: Tue May 31, 2005 11:19 pm
Posts: 11
Location: Brisbane, Australia
I've never used the subclass stuff in nhibernate but my general understanding of subclassing is that the subclass (Faculty) inherits the properties and methods of the parent class (User).

Please correct me if I'm wrong...

Are you sure subclassing is the relationship you want? By making Faculty a subclass of User you are saying that Faculty is a specific type of user.
Code:
Internal class Faculty : User


Say, for example, you had Student and Teacher objects, I'd expect them to be subclasses of User - each subclass adding properties to the basic User object specific to Students and Teachers respectively.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 10:38 am 
Newbie

Joined: Thu Jun 02, 2005 12:00 pm
Posts: 8
You're absolutely correct. I do want the subclasses (Faculty) to inherit the properties of the base class (User), however, the NHibernate.Mapping.Attributes attributes or the thing that parses them is listing them twice in the XML mapping file. For instance, FirstName is only defined in the User class, but in the XML mapping file it says that there is a FirstName property in BOTH User and Faculty. When I go to retrieve the Faculty object from my database, it says that the FirstName column doesn't exist, along with all of the other properties that are defined in User which are DUPLICATED in the Faculty XML mapping.

I looked at the code for the MapGenerator in the NHibernate.Mapping.Attributes project and it looks like it only wants to retrieve the properties from the base class. I don't think it's a bug or anything, I just think I may not be using these particular properties correctly. Has anyone used them successfully?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 10:35 pm 
Beginner
Beginner

Joined: Tue May 17, 2005 7:25 pm
Posts: 43
Location: Somewhere, USA
What you are describing is a know issue with the library. I have been working on fix and plan to check it in soon.


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