473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Mapping a Decorator Pattern in NHibernate

Hi!
Hope you can help my with you issue...
I made a domain model (http://cedev.com.ar/model.jpg) and what I'm
trying to is the NHibernate mappings to persist it. (It's uses the
Decorator Pattern, of course..)
It's importante to know that a Person might be a Student and a Tutor
at the same time (that's why it's not a simple inheritance)
I created a table for ConcretePerson, another one for SystemUser (only
with the Id), other for Tutor and other for Student (only with the Id
too). The problem is that a partner is criticizing me (and with good
reasons) that the ConcretePerson table should have fields like
"IsStudent", "IsTutor" and so on, to improve the performance and don't
let NH make a lot of joins to find a student...

What can I do??

Thanks in Advance!,
Diego

Jun 10 '07 #1
3 3151
hi,
hope this will help you
http://www.codeproject.com/aspnet/NH...select=2055053

Regards,
Husam al-aáraj
www.aaraj.net

"Diego Jancic" wrote:
Hi!
Hope you can help my with you issue...
I made a domain model (http://cedev.com.ar/model.jpg) and what I'm
trying to is the NHibernate mappings to persist it. (It's uses the
Decorator Pattern, of course..)
It's importante to know that a Person might be a Student and a Tutor
at the same time (that's why it's not a simple inheritance)
I created a table for ConcretePerson, another one for SystemUser (only
with the Id), other for Tutor and other for Student (only with the Id
too). The problem is that a partner is criticizing me (and with good
reasons) that the ConcretePerson table should have fields like
"IsStudent", "IsTutor" and so on, to improve the performance and don't
let NH make a lot of joins to find a student...

What can I do??

Thanks in Advance!,
Diego

Jun 10 '07 #2
Hi,
I already read that article, which part do you consider important ?

Thanks,
Diego

Jun 10 '07 #3
Diego Jancic wrote:
Hi!
Hope you can help my with you issue...
I made a domain model (http://cedev.com.ar/model.jpg) and what I'm
trying to is the NHibernate mappings to persist it. (It's uses the
Decorator Pattern, of course..)
It's importante to know that a Person might be a Student and a Tutor
at the same time (that's why it's not a simple inheritance)
I created a table for ConcretePerson, another one for SystemUser (only
with the Id), other for Tutor and other for Student (only with the Id
too). The problem is that a partner is criticizing me (and with good
reasons) that the ConcretePerson table should have fields like
"IsStudent", "IsTutor" and so on, to improve the performance and don't
let NH make a lot of joins to find a student...
If you want to use inheritance, you can model it in two ways: single
table inheritance, which requires a discriminator column (e.g.
PersonType) and multi-table inheritance, which has per type its own
table (there are variants on this, but it all comes down to that).

Single table inheritance is faster as you don't have to use joins with
the tables of the sub/super types. It's also less usable as you can't
create mandatory relations between subtypes and another entity mapped
on another table: the fk fields have to be nullable in that regard.

While inheritance is a must-have feature for o/r mappers, it is often
mis-used. The main issue here is that people tend to forget that a type
is fixed: once you have an instance of an entity of type T saved into
the DB, that instance is fixed. You can't change an object in-memory
into a different type it doesn't have as well.

A typical example of misuse of inheritance is often seen in structures
where a 'role' would have been better. Your situation is such a case:
Say you create a new student instance. After a while that student
becomes a tutor. That student doesn't change type. So you have to
create a new entity instance, namely of type tutor, and save that with
the data of the student. Then, after a month, the student gets bored
and isn't a tutor anymore. Same thing happens.

Better is to use a role system in THIS situation: Student has the role
of tutor or not. You could also argue (if person is also used to store
people who were students but now have graduated) that person is such a
candidate, thus that person should have a role 'student' and thus could
have multiple roles.

The typical indication that you need such a mechanism is when you see
that the types can change on a live instance.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Jun 11 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: object-relational persistence mapping | last post by:
Someone can tell me where I find a good Object-Relational Mapping library.
1
by: erin.sebastian | last post by:
Hello All, I am new to hibernate and new to nHibernate. I created a small app and when i try and run it i get the error i posted at the bottom of this message. I am using the helper class that...
1
by: Ram | last post by:
Hey, I'm having a trouble mapping a connecting between 2 of my tables. We have 2 tables - the simplest "dept", "emp" tables which are mapped to 2 classes. Class Dept contains 2 properties for...
1
by: sternr | last post by:
Hey, I'm using NHibernate version: 1.0.0.2 My Mapping documents: <class name="DM.Book" table="Books"> <id column="bookId" name="bookId"> <generator class="assigned" /> </id> <property...
5
by: Doug | last post by:
I am looking at using the decorator pattern to create a rudimentary stored proc generator but am unsure about something. For each class that identifies a part of the stored proc, what if I want to...
4
by: thomas.karolski | last post by:
Hi, I would like to create a Decorator metaclass, which automatically turns a class which inherits from the "Decorator" type into a decorator. A decorator in this case, is simply a class which...
11
by: George Sakkis | last post by:
I have a situation where one class can be customized with several orthogonal options. Currently this is implemented with (multiple) inheritance but this leads to combinatorial explosion of...
8
by: Chris Forone | last post by:
hello group, is there a possibility to implement the decorator-pattern without new/delete (nor smartpt)? if not, how to ensure correct deletion of the objects? thanks & hand, chris
5
by: proxyuser | last post by:
The context of this question is actually from the book "C# 3.0 Design Patterns" (Bishop). She makes the point that one of the reasons you'd use Decorator is if you can't change the original...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.