-->
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.  [ 5 posts ] 
Author Message
 Post subject: Class Inheritance
PostPosted: Sat Mar 21, 2009 5:51 am 
Newbie

Joined: Sat Mar 21, 2009 5:22 am
Posts: 10
Hi, I am fairly new to NH and have encountered an issue.

Could someone please offer me some advice?

I have 3 classes... Entity, WorkItem and InvoiceItem.
I have 2 tables... WorkItem and InvoiceItem.

WorkItem inherits from Entity and InvoiceItem Inherits from WorkItem.

I have created as abstract class Entity as all my classes will contain the properties Id and Version.

This code works fine
var test = session.CreateCriteria(typeof(WorkItem)).List<WorkItem>();

The sql generated by this code tries to map Id and Version to the InvoiceItem Table. However, it should be creating an Inner Join bewteen the InvoiceItem table and the WorkItem Table.
var test = session.CreateCriteria(typeof(InvoiceItem)).List<InvoiceItem>();


Below is my comfiguration mapping.

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Example.Entities"
namespace="Example.Entities">
<class name="Entity" lazy="true" abstract="true" polymorphism="implicit">

<id name="Id">
<generator class="guid" />
</id>

<version name="Version" type="Example.Entities.Hibernate.UserTypeTimestamp,
Example.Entities.Hibernate" unsaved-value="null" generated="always" />

</class>
</hibernate-mapping>


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Example.Entities"
namespace="Example.Entities">
<union-subclass name="WorkItem" extends="Entity">
<property name="Label"/>
</union-subclass>
</hibernate-mapping>


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Example.Entities"
namespace="Example.Entities">
<joined-subclass name="InvoiceItem" extends="WorkItem">
<key column="Id"/>
<property name="Number"/>
</joined-subclass>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: Is this a bug with NHibernate
PostPosted: Sat Mar 21, 2009 10:19 am 
Newbie

Joined: Sat Mar 21, 2009 5:22 am
Posts: 10
Could this be a fundamental bug with NHibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 22, 2009 8:09 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I haven't used union-join, yet, since I'm still working with 1.2. But from the documention, I would say this is correct. Union-join is a "table-per-concrete-class" strategy. That means, every subclass has its own table, which contains all columns. In my understanding there won't be any joins, just unions.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Is the a solution to this?
PostPosted: Sun Mar 22, 2009 9:49 am 
Newbie

Joined: Sat Mar 21, 2009 5:22 am
Posts: 10
Thanks for the reply. Greatly appreciated.

Do you know if this can be achieved with NHibernate?

Any advice would be greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 22, 2009 10:09 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
What exactly do you want to do ? A base table with the fields from the abstract class and a second table for each subclass that only contains the subclasses fields ? Then you need this approach:

http://www.nhforge.org/doc/nh/en/index.html#inheritance-tablepersubclass-discriminator

_________________
--Wolfgang


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