-->
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: <T> Generic Abstract Classes
PostPosted: Tue Jan 27, 2009 6:16 am 
Newbie

Joined: Wed Aug 13, 2008 10:00 am
Posts: 7
NHibernate version:2.0.1 GA

Hi,

I have these classes and xml files.

public abstract class AbstractClass1
{
private int _id;
private string _info;

public virtual int Id
{
get { return _id; }
set { _id = value; }
}

public virtual string Info
{
get { return _info; }
set { _info = value; }
}
}

<class name="AbstractClass1" abstract="true" table="AbstractClass1" discriminator-value="0">
<id name="Id" type="int" unsaved-value="-1">
<generator class="identity"/>
</id>
<discriminator column="TypeAbstractClass1" type="byte" />

<property name="Info" type="string"/>

<subclass name="ExtendedAbstractClass1_1" discriminator-value="1">
<join table="ExtendedAbstractClass1_1">
<key column="Id_AbstractClass1"/>
...
</join>
</subclass>

<subclass name="ExtendedAbstractClass1_2" discriminator-value="2">
</subclass>
</class>

public abstract class AbstractClass2<TAbstract> where TAbstract : AbstractClass1
{
private int _id;
private TAbstract _abstract;

public virtual int Id
{
get { return _id; }
set { _id = value; }
}

public virtual TAbstract AbstractClass1
{
get{return _abstract;}
set{_abstract = value;}
}
}

public class ExtendedAbstractClass2_1 : AbstractClass2<ExtendedAbstractClass1_1>
{
...
...
}

<class name="AbstractClass2" abstract="true" table="AbstractClass_2" discriminator-value="0">
<id name="Id" type="int" unsaved-value="-1">
<generator class="identity"/>
</id>
<discriminator column="TypeAbstractClass2" type="byte" />

<many-to-one name="AbstractClass1"
column="Id_AbstractClass1"
not-null="true"
fetch="select"/>

<subclass name="ExtendedAbstractClass2_1" discriminator-value="1">
<join table="ExtendedAbstractClass2_1">
<key column="Id_AbstractClass1"/>
<property name="..." type="string"/>
<property name="..." type="string"/>
</join>
</subclass>

<subclass name="ExtendedAbstractClass2_2" discriminator-value="2">
</subclass>
</class>

I know the naming might be confusing, sorry for that.
I get and error on the build of "AbstractClass2".hbm.xml file saying that it can't load type "AbstractClass2".
This works if I dont't make AbstractClass2 generic.

I would like to get a strongly typed object of type AbstractClass1 in the ExtendedAbstractClasses from AbstractClass2. Is this possible? Is this the right approach?
Any help would be appreciated.


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.