473,811 Members | 2,859 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3166
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
1370
by: object-relational persistence mapping | last post by:
Someone can tell me where I find a good Object-Relational Mapping library.
1
13713
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 can be found here http://blogs.intesoft.net/simon/articles/16.aspx#36 . Does anyone know why this error might occur.. i have NO IDEA.... if you require anymore information please let me know and i will send it through. Thanks in advance! Erin
1
2562
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 emps - 1 for manager and the second for workers (Collection). How can I map this? We can add additional fields in the emp table that indicates the property in the depts?
1
12741
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 column="name" name="name" />
5
1818
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 add a value dynamically. I'm including some code to show what I mean. This is real basic on what I want to do: using System; namespace ClassLibrary1 {
4
2474
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 has all of its decorator implementation inside a decorator() method. Every other attribute access is being proxied to decorator().getParent(). Here's my attempt: -------------------------------------------------------
11
1722
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 subclasses as more orthogonal features are added. Naturally, the decorator pattern comes to mind (not to be confused with the the Python meaning of the term "decorator"). However, there is a twist. In the standard decorator pattern, the decorator...
8
2891
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
3647
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 component class. On p. 17, she explains a code example: "...this code deviates from the pattern laid out...there is no IComponent interface. This is perfectly acceptable; the decorators can inherit directly from the component and maintain an...
0
9722
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10393
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10124
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.