-->
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: Base class with both subclass and joined-subclass?
PostPosted: Sat Aug 13, 2005 6:05 pm 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
Hi,

I've got a situation where we have a base class with multiple subclasses, however some of the subclasses don't have any additional properties to the base class while others do. As a result, I want to provide an extra table only for the subclasses that need to express extra property values.

So, my base class mapping:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="Framework.Core.Entities" assembly="Framework.Core">

   <class name="InputProfile" table="InputProfiles">
      
      <id name="id" column="InputProfileID" unsaved-value="0" access="field">
         <generator class="native" />
      </id>
      
      <discriminator column="InputInterface" type="System.Byte"/>
      
      <version name="version" column="Version"  access="field"/>
      
      <property name="created" column="Created" update="false" access="field"/>
      <property name="deleted" column="Deleted" access="field"/>
      <property name="inputInterface" column="InputInterface" access="field" />
      <property name="modified" column="Modified" update="false" access="field"/>
      <many-to-one name="parentUser" column="ParentUserID" class="User" access="field" cascade="all"/>
   
   </class>
   
</hibernate-mapping>


A subclass without additional properties (although they may come later):

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="Framework.Core.Entities" assembly="Framework.Core">

   <subclass name="SmtpInputProfile" extends="InputProfile" discriminator-value="1">
   
   </subclass>

</hibernate-mapping>


And a subclass with additional properties in it's own table:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="Framework.Core.Entities" assembly="Framework.Core">
   
   <joined-subclass name="FtpInputProfile" extends="InputProfile" table="FtpInputProfiles">
   
      <key column="FtpInputProfileID" />
      
      <property name="welcomeMessage" column="WelcomeMessage" access="field" />
            
   </joined-subclass>
   
</hibernate-mapping>


Obviously these are only examples and the classes that use the table per joined subclass actually have many more additional properties.

When I try to do this I'm getting a mapping exception:

Code:
[MappingException: Could not format discriminator value 'Framework.Core.Entities.InputProfile' to sql string using the IType NHibernate.Type.ByteType]
   NHibernate.Persister.EntityPersister..ctor(PersistentClass model, ISessionFactoryImplementor factory) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-0.9.0.0\src\NHibernate\Persister\EntityPersister.cs:147
   NHibernate.Persister.PersisterFactory.Create(PersistentClass model, ISessionFactoryImplementor factory) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-0.9.0.0\src\NHibernate\Persister\PersisterFactory.cs:43
   NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, Settings settings) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-0.9.0.0\src\NHibernate\Impl\SessionFactoryImpl.cs:139
   NHibernate.Cfg.Configuration.BuildSessionFactory() in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-0.9.0.0\src\NHibernate\Cfg\Configuration.cs:894


Is this a bug, or is what I'm trying to accomplish not possible?

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 15, 2005 12:37 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
NHibernate don't support mixing subclass and joined-subclass.

You should be able to solve this issue using only joined-subclass...

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


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.