Table per subclass mapping strategy when inheritance is more than 1 level deep

11 views
Skip to first unread message

Drakiula

unread,
May 25, 2009, 5:29:50 AM5/25/09
to nhusers
Hi, I have the following class inheritance hierarchy:

public class A {}

public class B : A {}

public class C : B {}

public class D : B {}

In the database I have tables A, B, C, D where:

- B has a foreign key relationship to A;
- C and D have foreign key relationships to B;

Both foreign key relationships are established using the PK field of
the tables(PK field type is Decimal).

On top of that, both base classes contain a discriminator column that
indicates the inheritor type.

Question: is this mapping scenario possible in NHibernate(table per
subclass, using the mentioned class inheritance hierarchy)?
If the answer is yes, how should the XML mapping file look like? Are
nested <joined-subclass /> elements allowed/supported?

Thanks in advance for your answer,
Dragos

Fabio Maulo

unread,
May 25, 2009, 8:56:36 AM5/25/09
to nhu...@googlegroups.com
You can't mix <subclass> with <joined-subclass>
You should use <subclass> and <join>
About multiple circular reference try to create it by hand in your RDBMS and then insert something with pure SQL (by hand again).

2009/5/25 Drakiula <haiduc...@gmail.com>



--
Fabio Maulo

Drakiula

unread,
May 25, 2009, 10:23:40 AM5/25/09
to nhusers
Thanks for the answer.

Can you please provide a sample full mapping for my scenario?

Fabio Maulo

unread,
May 25, 2009, 1:32:13 PM5/25/09
to nhu...@googlegroups.com
2009/5/25 Drakiula <haiduc...@gmail.com>


Thanks for the answer.

Can you please provide a sample full mapping for my scenario?

--
Fabio Maulo
Reply all
Reply to author
Forward
0 new messages