-->
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.  [ 1 post ] 
Author Message
 Post subject: Version 7.0 to 8.4 - Inheritance mapping problem
PostPosted: Tue Jun 07, 2005 4:27 pm 
Newbie

Joined: Tue Jun 07, 2005 4:13 pm
Posts: 2
Location: Orillia, Ontario, Canada
Hey there just wanted to say to the dev team - you guys rock, and keep up the good work. Before I chose to go with NHibernate i looked at quite a few different other options, and found that NHibernate seemed to fit the way I want to work best.
Anyhow on to the question/issue:
<thesetup>
/*note this was quite happy in ver. 0.7 */

I have a hierarchy as follows -> BasePerson and BaseLocation inherit from BaseEntity. All other people or locations inherit from
BasePerson or BaseLocation. BaseEntity has an inner class CommonInfo which contains basic contact information for the person or location.
As of ver 0.7 I had not mapped BasedEnity, but had mappings for BasePerson and BaseLocation with contained subclass mappings for each specific
type of person or location and the mapping to CommonInfo.
The mapping of CommonInfo was specified in each of these mappings, and then specified within the CommonInfo mapping as specific one-to-one
mappings.

BaseLocation and BasePerson Mapping:
Code:
<class  name="LysiasDesigns.Osiris.DataObjects.BaseLocation,Osiris.DataObjects" table="Locations" dynamic-insert="true" 
dynamic-update="true">
      <id name="ID" column="location_id"  unsaved-value="00000000-0000-0000-0000-000000000000" type="Guid">
         <generator class="guid" />
      </id>      
      <discriminator column="locationtype" type="String"/>
      <property name="Name" column="name"/>
      <one-to-one name="Common" cascade="all"/>
      <property name="Hash" column="location_hash" />
      <set name="GeneralContacts" inverse="true" lazy="true" cascade="save-update">
         <key column="gc_id"/>
         <one-to-many class="LysiasDesigns.Osiris.DataObjects.GeneralContact,Osiris.DataObjects"/>
      </set>
      <many-to-one name="DenominationType" class="LysiasDesigns.Osiris.DataObjects.Denomination,Osiris.DataObjects"   
column="denom_id"/>
      <bag name="Products" inverse="true" lazy="true" cascade="save-update">
         <key column="product_id"/>
         <one-to-many class="LysiasDesigns.Osiris.DataObjects.Inventory.Product,Osiris.DataObjects"/>
      </bag>
      
      <!-- Beginning of Funeral Home type mappings. -->
      <subclass name="LysiasDesigns.Osiris.DataObjects.FuneralHome,Osiris.DataObjects" discriminator-value="1">
         <property name="BusinessCode" column="businessCode"/>         
         <!-- <set name="FuneralDirectors" inverse="true" lazy="false" cascade="save-update">
            <key column="fh_id"/>
            <one-to-many class="LysiasDesigns.Osiris.DataObjects.FuneralDirector,Osiris.DataObjects"/>
         </set> -->
         <list name="FuneralDirectors" inverse="true" lazy="false" cascade="save-update">
            <key column="fh_id"/>
            <index column ="fd_id"/>
            <one-to-many class="LysiasDesigns.Osiris.DataObjects.FuneralDirector, Osiris.DataObjects"/>
         </list>
      </subclass>
      
      <!-- Beginning of Hospital type mappings. -->
      <subclass name="LysiasDesigns.Osiris.DataObjects.Hospital,Osiris.DataObjects" discriminator-value="2">
      </subclass>
      <!-- Beginning of Flowershop type mappings. -->
      <subclass name="LysiasDesigns.Osiris.DataObjects.Flowershop,Osiris.DataObjects" discriminator-value="3">
      </subclass>
      <!-- Beginning of Newspaper type mappings. -->
      <subclass name="LysiasDesigns.Osiris.DataObjects.Newspaper,Osiris.DataObjects" discriminator-value="4">
      </subclass>
      <!-- Beginning of Manufacturer type mappings. -->
      <subclass name="LysiasDesigns.Osiris.DataObjects.Manufacturer,Osiris.DataObjects" discriminator-value="5">
      </subclass>
      <!-- Beginning of Church type mappings. -->
      <subclass name="LysiasDesigns.Osiris.DataObjects.Church,Osiris.DataObjects" discriminator-value="6">      
         <set name="ClergyCollection" inverse="true" lazy="false" cascade="save-update">
            <key column="chu_id"/>
            <one-to-many class="LysiasDesigns.Osiris.DataObjects.Clergy,Osiris.DataObjects"/>
         </set>
      </subclass>
   </class>
   <!-- Beginning of PERSON type mappings. -->
   <class  name="LysiasDesigns.Osiris.DataObjects.BasePerson,Osiris.DataObjects" table="BasePerson" dynamic-insert="true" 
dynamic-update="true">
      <id name="ID" column="person_id"  unsaved-value="00000000-0000-0000-0000-000000000000" type="Guid">
         <generator class="guid" />
      </id>      
      <property name="FirstName" column="firstname"/>
      <property name="LastName" column="lastname"/>
      <one-to-one name="Common" cascade="all"/>
      <property name="Hash" column="person_hash" />
      <many-to-one name="DenominationType" class="LysiasDesigns.Osiris.DataObjects.Denomination,Osiris.DataObjects"   
column="denom_id"/>

      <!-- Beginning of Funeral Director type mappings. -->      
      <joined-subclass name="LysiasDesigns.Osiris.DataObjects.FuneralDirector,Osiris.DataObjects" table="FuneralDirector">
         <key column="fd_id"/>
         <many-to-one name="Funeral_Home" class="LysiasDesigns.Osiris.DataObjects.FuneralHome,Osiris.DataObjects" 
column="fh_id"/>
      </joined-subclass>
      <!-- Beginning of General Contact type mappings. -->   
      <joined-subclass name="LysiasDesigns.Osiris.DataObjects.GeneralContact,Osiris.DataObjects" table="GeneralContact">
         <key column="gc_id"/>
         <many-to-one name="Parent" class="LysiasDesigns.Osiris.DataObjects.BaseLocation,Osiris.DataObjects" 
column="location_id"/>
      </joined-subclass>
      <!-- Beginning of Coroner type mappings. -->   
      <joined-subclass name="LysiasDesigns.Osiris.DataObjects.Coroner,Osiris.DataObjects" table="Coroner">
         <key column="cor_id"/>
         <property name="IsActive" column="is_active"/>
      </joined-subclass>
      <!-- Beginning of Clergy type mappings. -->   
      <joined-subclass name="LysiasDesigns.Osiris.DataObjects.Clergy,Osiris.DataObjects" table="Clergy">
         <key column="clg_id"/>      
         <property name="Prefix" column="prefix"/>   
      </joined-subclass>
   </class>


CommonInfo Mapping:

Code:
<class  name="LysiasDesigns.Osiris.DataObjects.CommonInfo,Osiris.DataObjects" table="CommonInfo">
      <id name="ID" column="common_id"  unsaved-value="00000000-0000-0000-0000-000000000000" type="Guid">
         <!-- <generator class="assigned" /> -->
         <generator class="foreign">
            <param name="property">Parent</param>
         </generator>
      </id>
      <property name="Phone1" column="phone1"/>
      <property name="Phone2" column="phone2"/>
      <property name="Phone3" column="phone3"/>
      <property name="Phone4" column="phone4"/>
      <property name="Email1" column="email1"/>
      <property name="Email2" column="email2"/>
      <property name="Email3" column="email3"/>
      <property name="Website" column="website"/>
      <property name="Notes" column="notes"/>
      <property name="Hash" column="common_hash" />
      <one-to-one name="Parent" class="LysiasDesigns.Osiris.DataObjects.BaseLocation,Osiris.DataObjects" constrained="false"/>
      <one-to-one name="Parent" class="LysiasDesigns.Osiris.DataObjects.BasePerson,Osiris.DataObjects" constrained="false"/>
      <one-to-one name="Parent" class="LysiasDesigns.Osiris.DataObjects.ClientInfo,Osiris.DataObjects" constrained="false" />
      <!--
      <bag name="AddressCollection" inverse="true" cascade="all" table="Address">
         <key column="common_id"/>
         
      </bag>
      -->
      <map name="AddressCollection" inverse="true" cascade="all" table="Address" order-by="isMailing DESC">
         <key column="common_id"/>
         <index column="address_id" type="Guid"/>
         <one-to-many class="LysiasDesigns.Osiris.DataObjects.AddressInfo,Osiris.DataObjects"/>
      </map>
   </class>


</thesetup>

<theproblem>

And now the problem. I'm now trying to upgrade to ver 0.8.4, things compile fine, but when NHibernate goes to load up the persistent

classes I'm getting an error about duplicate field names when it is trying to load the CommonInfo mapping.

NHibernate log:
Quote:
DEBUG, 2005-06-07 15:10:00,812 , [1880] , NHibernate.Cfg.Environment..cctor(:0) , no hibernate settings in app.config/web.config were found
INFO , 2005-06-07 15:10:00,828 , [1880] , NHibernate.Cfg.Configuration.AddAssembly(:0) , Found mapping documents in assembly:
LysiasDesigns.Osiris.DataObjects.CommonInfo.hbm.xml
INFO , 2005-06-07 15:10:00,875 , [1880] , NHibernate.Dialect.Dialect..ctor(:0) , Using dialect: NHibernate.Dialect.MsSql2000Dialect
INFO , 2005-06-07 15:10:00,890 , [1880] , NHibernate.Cfg.Binder.BindRootClass(:0) , Mapping class: LysiasDesigns.Osiris.DataObjects.CommonInfo
-> CommonInfo
DEBUG, 2005-06-07 15:10:00,906 , [1880] , NHibernate.Cfg.Binder.BindProperty(:0) , Mapped property: ID -> common_id, type: Guid
DEBUG, 2005-06-07 15:10:00,921 , [1880] , NHibernate.Cfg.Binder.BindProperty(:0) , Mapped property: Phone1 -> phone1, type: String
DEBUG, 2005-06-07 15:10:00,921 , [1880] , NHibernate.Cfg.Binder.BindProperty(:0) , Mapped property: Phone2 -> phone2, type: String
DEBUG, 2005-06-07 15:10:00,921 , [1880] , NHibernate.Cfg.Binder.BindProperty(:0) , Mapped property: Phone3 -> phone3, type: String
DEBUG, 2005-06-07 15:10:00,921 , [1880] , NHibernate.Cfg.Binder.BindProperty(:0) , Mapped property: Phone4 -> phone4, type: String
DEBUG, 2005-06-07 15:10:00,921 , [1880] , NHibernate.Cfg.Binder.BindProperty(:0) , Mapped property: Email1 -> email1, type: String
DEBUG, 2005-06-07 15:10:00,921 , [1880] , NHibernate.Cfg.Binder.BindProperty(:0) , Mapped property: Email2 -> email2, type: String
DEBUG, 2005-06-07 15:10:00,921 , [1880] , NHibernate.Cfg.Binder.BindProperty(:0) , Mapped property: Email3 -> email3, type: String
DEBUG, 2005-06-07 15:10:00,921 , [1880] , NHibernate.Cfg.Binder.BindProperty(:0) , Mapped property: Website -> website, type: String
DEBUG, 2005-06-07 15:10:00,921 , [1880] , NHibernate.Cfg.Binder.BindProperty(:0) , Mapped property: Notes -> notes, type: String
DEBUG, 2005-06-07 15:10:00,921 , [1880] , NHibernate.Cfg.Binder.BindProperty(:0) , Mapped property: Hash -> common_hash, type: String
DEBUG, 2005-06-07 15:10:00,937 , [1880] , NHibernate.Cfg.Binder.BindProperty(:0) , Mapped property: Parent, type: BaseLocation
DEBUG, 2005-06-07 15:10:00,937 , [1880] , NHibernate.Cfg.Binder.BindProperty(:0) , Mapped property: Parent, type: BasePerson
ERROR, 2005-06-07 15:10:00,953 , [1880] , NHibernate.Cfg.Configuration.Add(:0) , Could not compile the mapping document
NHibernate.MappingException: Duplication mapping for property: LysiasDesigns.Osiris.DataObjects.CommonInfo.Parent
at NHibernate.Mapping.PersistentClass.AddNewProperty(Property p)
at NHibernate.Cfg.Binder.PropertiesFromXML(XmlNode node, PersistentClass model, Mappings mappings)
at NHibernate.Cfg.Binder.BindRootClass(XmlNode node, RootClass model, Mappings mappings)
at NHibernate.Cfg.Binder.BindRoot(XmlDocument doc, Mappings model)
at NHibernate.Cfg.Configuration.Add(XmlDocument doc)


</theproblem>

I've traced the location where the error is being throw to NHibernate-1.1.Mapping.PersistentClass.cs AddNewProperty(Property p) [line 176].
Basically I'm wondering why this was added/changed between the versions. I'm also wondering about what my options could be to get things back up

and running without reverting to 0.7. I have to say that I'm not too excited about sub-classing CommonInfo multiple times to make this work.
Any ideas would be great, Thanks.[/code]


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

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.