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.  [ 8 posts ] 
Author Message
 Post subject: subclass with extended properties in another table
PostPosted: Mon Jun 18, 2007 7:46 am 
Beginner
Beginner

Joined: Tue Jan 17, 2006 12:55 pm
Posts: 49
I am trying to model a subclass using table-per-hierarchy.

My subclass also has extended properties which are held in another table.

Could someone give me some idea as to how to map this? I cannot find anyway to add a property from another table.

The nearest I can find is to add the properties of the other table as a component class, but this seems to me to be an un-intuitive way of doing it which is inconsistent with the rest of the object hierarchy.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 2:04 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
The quick answer is: If you have a separate table holding properties for a given subclass, your strategy isn't really table-per-hierarchy. :)

Unfortunately, NH does not yet support mixed-mode inheritance. In general the way to "add a property from another table" is by using joined-subclass, but this can't be done in the context of a single-table hierarchy. From the docs (section 8.1): "NHibernate does not support mixing
<subclass> mappings and <joined-subclass> mappings inside the same <class> element."


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 3:45 am 
Beginner
Beginner

Joined: Tue Jan 17, 2006 12:55 pm
Posts: 49
marcal wrote:
The quick answer is: If you have a separate table holding properties for a given subclass, your strategy isn't really table-per-hierarchy. :)


Well it is really... there are loads of common common/properties in the main table.. the seperate table just holds a couple columns with very specific properties and this is a link table to another entity specific to the subclass.

If there is no specific support for this I think I am going to have to kludge this by creating a specific association class


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 4:39 am 
Beginner
Beginner

Joined: Tue Jan 17, 2006 12:55 pm
Posts: 49
Another idea!

Maybe I should mimic table-per-subclass by using views? Any comments?

I have just tried this and it seems to do the job OK. although this seems like a bit of a kludge, having to alter the database schema to get around a mapping problem.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 5:07 am 
Beginner
Beginner

Joined: Tue Jan 17, 2006 12:55 pm
Posts: 49
Boll*x

Can't do it this way... cannot save to database since it uses multiple tables.

Error: View or function 'DownloadPackages' is not updatable because the modification affects multiple base tables.

Here is my new mapping, which is against a view called download packages:


Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Narrowstep.Entities" namespace="Narrowstep.Entities">
   <joined-subclass name="DownloadPackage" extends="Narrowstep.Entities.Vlip, Narrowstep.Entities" table="DownloadPackages">
      <key column="DownloadPackageID" />
      <property name="IsEnabled" column="IsEnabled" type="boolean" />
      <many-to-one name="PaymentRule" class="PaymentRule" column="PaymentRuleID" lazy="false" outer-join="true" />
   </joined-subclass>
   
</hibernate-mapping>


The original mapping was just a simple sublass element, but this did not allow me to use extended properties in the other table.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 5:07 am 
Beginner
Beginner

Joined: Tue Jan 17, 2006 12:55 pm
Posts: 49
.........................................................................................................


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 10:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
dircums,

You can download the latest snapshot, and then you can use the <join> mapping to achieve what you want.

http://jira.nhibernate.org/browse/NH-466

Karl


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 10:37 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
dircums wrote:
Can't do it this way... cannot save to database since it uses multiple tables.

Error: View or function 'DownloadPackages' is not updatable because the modification affects multiple base tables.

Here is my new mapping, which is against a view called download packages:


Darn, I'm ashamed that I didn't think of using views. It is still possible: if you are using SQL 2000/5 you should be able to build INSTEAD OF triggers to allow modifications to the underlying tables.

Quote:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Narrowstep.Entities" namespace="Narrowstep.Entities">
   <joined-subclass name="DownloadPackage" extends="Narrowstep.Entities.Vlip, Narrowstep.Entities" table="DownloadPackages">
...   </joined-subclass>
   
</hibernate-mapping>


The original mapping was just a simple sublass element, but this did not allow me to use extended properties in the other table.


Interesting, I would have thought that you would use the view to pull the "DownloadPackages" columns into the main table and use <subclass> to map.


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