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.  [ 2 posts ] 
Author Message
 Post subject: Mapping Properties of Different Classes to Same Table
PostPosted: Sun Sep 09, 2007 3:28 pm 
Beginner
Beginner

Joined: Mon Nov 07, 2005 11:06 pm
Posts: 28
I have a mapping challenge and would love some advice...

I have a class EmailTemplate that consists of the following properties...
- FromAddress
- Subject
- Body

I have several classes that need to use EmailTemplate like this...

Solution class...
- int ID
- string Title
- EmailTemplate NewAccountEmailTemplate
- EmailTemplate ResetPasswordEmailTemplate

Invitation class...

- int ID
- etc...
- EmailTemplate InvitationReminderEmailTemplate

So, you can see I have several classes that need to have properties that are email templates. I know this is sort of like mapping components, except I do not want to store the email template in the same table as the parent class.

Instead, I would like to store ALL email templates in a single table EmailTemplates. I would like to use something like this...

EmailTemplates table
- ParentID int
- Title nvarchar(100)
- FromAddress nvarchar(100)
- Subject nvarchar(200)
- Body nvarchar(max)

And I would like to have an email template be uniquely identified by the combination of the ParentID col and the Title col. Then, the data might look something like this for the Solution's New Account Email Template...

ParentID = 20 (example id for solution)
Title = "Solution New Account Email Template"
From = "[email protected]"
Subject = "Test"
Body = "Test"

So, the combination of ParentID and Title would uniquely identify the email template and identify it as the exact one to use for Solution.NewAccouintEmailTemplate.

In an even better world, I would like to have my EmailTemplates table be something like this...

- ParentType
- ParentID
- Title
- etc...

where ParentType would be "Solution" or "Invitation", etc. Then, I would need to have a composite index that is based on three columns instead of two columns.

I do not even know where to start to map this kind of situation. I appreciate any help!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 10, 2007 11:10 am 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
There is a way to accomplish what you would like, although I wouldn't personally recommend it. You will not have proper foreign key constraints in the database. I would advise using an approach where you can properly constrain the data at the database level.

But to accomplish what you want you can use inheritance on your e-mail template. Use the ParentType column as the discriminator and then create a different EmailTemplate class for each type you want to apply the templates to. Then for each type map the ParentID column to the primary key value of the matching ParentType.

From NHibernate's perspective it should all work.


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