-->
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.  [ 3 posts ] 
Author Message
 Post subject: Can a Base Class (interface) be used to fill a collection?
PostPosted: Mon May 30, 2005 12:51 am 
Newbie

Joined: Sun May 15, 2005 11:39 pm
Posts: 17
Location: Australia
Hello all,

I have a base class (clsA) that has a number of subclasses (clsA1, clsA2...) . These objects relate many-to-one to another class (clsB).

I wish to have an ISet on clsB that contains all of the clsA instances. This collection needs to contain a hetergenous mix of the subclasses (clsA1, clsA2 etc).

I am having difficulty creating the map...

Quote:
Exception: NHibernate.WrongClassException
Message: Object with id: 71474 was not of the specified sublcass: OPWLibrary.CDT.iOPWCoreData (Discriminator: FCST )


Can someone please tell me, is it possible to get NH to achieve what I need?

I have included some extracts from my maps if they will help.

Thank you very much in advance,




Damien Sawyer

From clsB Map

Code:
<set  name="_oPWCoreDataItemsNH" access="field" inverse="true" lazy="true">
      <key column="cDataTypeID"/>
      <one-to-many class="OPWLibrary.CDT.iOPWCoreData,OPWLibrary"/>
</set>



From clsB Code

Code:
private ISet _oPWCoreDataItemsNH = new HashedSet();



From clsA{1,2...} Map


Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="OPWLibrary.CDT.iOPWCoreData, OPWLibrary"  table="tblCoreData">
     
      <id name="CoreDataID" column="iCoreDataID">
         <generator class="assigned" />
      </id>
      
      <discriminator column="cDataTypeID"/>
      
      <!--Out of interst, need to mark this as insert=false, update=false, because cDataTypeID is used above (as the discriminator)-->
      <many-to-one name="CoreDataType" column="cDataTypeID" insert="false" update="false" not-null="true"/>   
            
      <subclass   name="OPWLibrary.CDT.clsCDT_SOH, OPWLibrary"
                discriminator-value="SOH" >
       </subclass>
       
  ...      
       <subclass   name="OPWLibrary.CDT.clsCDT_FCST, OPWLibrary"
                discriminator-value="FCST" >
       </subclass>
      
   </class>
</hibernate-mapping>


From clsA Code

Code:
namespace OPWLibrary.CDT
{
   /// <summary>
   /// Summary description for iOPWCoreData.
   /// </summary>
   public interface iOPWCoreData
   {
         clsCoreDataType CoreDataType{get;set;}
         ...
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2005 5:07 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
At a glance I would say it should work. So it looks like a bug, can you please create a JIRA issue for it?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2005 8:25 pm 
Newbie

Joined: Sun May 15, 2005 11:39 pm
Posts: 17
Location: Australia
Thanks very much Sergey,

I've posted a Jira.


DS


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