-->
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.  [ 3 posts ] 
Author Message
 Post subject: Table per concrete class help
PostPosted: Wed Jan 09, 2008 7:53 am 
Beginner
Beginner

Joined: Sun Nov 18, 2007 10:39 am
Posts: 46
Location: Liverpool, England
Hi,
I'm fairly new to NHibernate, and am trying to use it to write an app against a legacy database. Mostly I'm getting on OK, but I'm a bit stuck with the following. I have a table, EDIAction, which has two many to one tables beneath it, EDIEmailRecipients and EDIFTPRecipients. These are defined as follows:

CREATE TABLE EDIEmailRecipients
ID int IDENTITY(1,1),
ActionID int,
Sender varchar(200),
etc

and

CREATE TABLE EDIFTPRecipients
ID int IDENTITY(1,1),
ActionID int,
Server varchar(50),
etc

So, both have their own identity columns, and both point back to the EDIAction table via the ActionID column.

In my code I have an interface IEDIRecipient which specifies two read only properties, RecipientType ("Email" or "FTP") and Summary, which basically provides a human readable description of the recipient.

In my EDIAction class I'd like to have a collection of IEDIRecipients. I'd like NHibernate to load the collection for me, and ideally I'd like to be able to add concrete classes to the collection and have NHibernate save them to the appropriate table. I don't need any other functionallity than this

I've looked at the docs on this, and it looks like I need to use the table per concrete class strategy (I'm not able to change the database schema), but I can't quite figure out how to do it. I've got mappings for each of the recipients tables, which work fine, but I'm not sure what to do with the <any> tag, or how to specify the collection of IEDIRecipients in my EDIAction mapping file.

Can anyone help?

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 5:48 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
Have you read http://www.hibernate.org/hib_docs/nhibe ... anymapping for <any>? You may not be able to set up such a collection directly, since it will require an intermediate table.

<any> and TPCC can be a real pain. Have you looked at simply supplying two separate collections on the object?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 10, 2008 11:40 am 
Beginner
Beginner

Joined: Sun Nov 18, 2007 10:39 am
Posts: 46
Location: Liverpool, England
I'd been looking at that part of the docs, but I couldn't figure out how to use any in this instance. My workaround at the moment is to use two seperate collections, as you suggested, and to provide a read only Recipients collection which I populate manually when required. Luckily there aren't generally many recipients per action, so it's not too expensive

Kev


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