I'm trying to map a deep class hierarchy and having trouble getting
the desired mapping. Here's an example:
Classes:
namespace Animals
{
public class Animal
{
public string SpeciesName { get; set; }
}
public class DomesticAnimal : Animal
{
public string Name { get; set; }
}
public class WildAnimal : Animal
{
public string Habitat { get; set; }
public bool IsPredator { get; set; }
}
public class EndangeredAnimal : WildAnimal
{
public string RedListID { get; set; }
public int Population { get; set; }
public string Status { get; set; }
}
public class IberianLinx : EndangeredAnimal
{
public int WhiskerLength { get; set; }
public int StripeCount { get; set; }
}
}
Mapping:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Animals">
<class name="Animals.Animal" abstract="true" table="Animal">
<id type="int" unsaved-value="0">
<generator class="native"/>
</id>
<discriminator column ="AnimalType" type="string" length="64"/>
<property name="SpeciesName"/>
<subclass name="Animals.DomesticAnimal" discriminator-
value="DomesticAnimal">
<property name="Name"/>
</subclass>
<subclass name="Animals.WildAnimal" discriminator-
value="WildAnimal">
<property name="Habitat"/>
<property name="IsPredator"/>
</subclass>
<subclass name="Animals.EndangeredAnimal" discriminator-
value="EndangeredAnimal">
<join table="EndangeredAnimal">
<key column="AnimalID"/>
<property name="RedListID"/>
<property name="Population"/>
<property name="Status"/>
</join>
<subclass name="Animals.IberianLinx" discriminator-
value="IberianLinx">
<property name="WhiskerLength"/>
<property name="StripeCount"/>
</subclass>
</subclass>
</class>
</hibernate-mapping>
When I generate the schema I get these:
create table Animal
(
id INT IDENTITY NOT NULL,
AnimalType NVARCHAR(64) not null,
SpeciesName NVARCHAR(255) null,
Name NVARCHAR(255) null,
Habitat NVARCHAR(255) null,
IsPredator BIT null,
WhiskerLength INT null,
StripeCount INT null,
primary key (id)
)
create table EndangeredAnimal (
AnimalID INT not null,
RedListID NVARCHAR(255) null,
Population INT null,
Status NVARCHAR(255) null,
primary key (AnimalID)
)
My problem is that I don't want IberianLynx's properties to be in
Animal, I need them to be in its immediate ancestor's table, i.e.
EndangeredAnimal. Why did they end up in Animal?
TIA
v64
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.