joined-subclass persitence

12 views
Skip to first unread message

Dan

unread,
Nov 24, 2009, 10:11:20 AM11/24/09
to nhusers
Within our system we have the concept of an employee. It contains your
basic employee data such as name, address, etc. We are in the process
of building a new application that needs this core employee data but
also needs to track information about a driver. Because a driver has
the same characteristics as an employee we are building this using the
joined-subclass functionality in NHibernate. The employee is the
"base" class, and the driver inherits from it, plus it has a few extra
properties.

Tables:
Employee
Name, Address, etc
Driver
Drivers license number, etc....

I'm finding that if a record has been persisted through the employee,
there isn't a way to load that employee a driver. Which makes sense
because a driver record with the employee's primary key was not
created. The reason that this is needed is due to the fact that we
have a set of "core" tables that are shared across many of our
applications. In this case that table is Employee. Depending upon what
application you're working with the context changes. Some applications
you're managing employees, and in another you're managing drivers.

So here is my question. Without writing some hack to insert a driver
record in the database; Is there a way that I can load an employee in
the context of a driver and have NHibernate understand that once it is
persisted the employee record is an update, and the driver record
would be an insert if it is the first time opening it in the driver
context? Else, it is just an update to both tables.

Thanks,
Dan

Germán Schuager

unread,
Nov 24, 2009, 10:18:51 AM11/24/09
to nhu...@googlegroups.com
I think that a one-to-one mapping with cascade="save-update" might work.


--

You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.



Dan Normington

unread,
Nov 24, 2009, 10:25:52 AM11/24/09
to nhu...@googlegroups.com
Germán, thanks for the advice. I ran into that solution when I first started the design but I was hoping I could take a more object oriented approach. Based upon my results it looks like using a one-to-one is probably going to be the way I'll have to go.
 
Thanks again


From: Germán Schuager <gsch...@gmail.com>
To: nhu...@googlegroups.com
Sent: Tue, November 24, 2009 9:18:51 AM
Subject: Re: [nhusers] joined-subclass persitence
Reply all
Reply to author
Forward
0 new messages