views:

66

answers:

1

Hi,

I'm trying to map two domain entities to the same table. We're doing a smart entity for our domain model, so we have the concept of an Editable Address and a readonly Address. I have both mapped using Classmaps, and everything seems to go fine until we try to export the schema using the SchemaExport class from NHibernate. It errors out saying the table already exists.

I assume it's something simple that I'm just not seeing.

Any ideas?

Thanks

Update

There are a couple of other things I didn't mention which I should have. I appreicate those that answered so far, but they don't work for us.

One is that we have a single address table, not include the columns in whatever entities have an address.

The other is that we can't use a common base class. For editable objects, we have a super class which adds validation behaviors to the subclasses. The readonly objects don't need this behavior though and should not have these behaviors.

I have considered an interface, but then I believe I end up in a situtation where you can cast a readonly object to this interface and then changes its values (since presumably NHibernate would use said interface to hydrate the object).

So if there's another way to acomplish this, or if mapping via an interface won't have the problem I described, please let me know. I'm still learning NHibernate.

Thanks again!

+2  A: 

Create one base abstract class entity which you will later extend to the Editable Address and the ReadOnly Address.

jpabluz
Hi, this won't work for use, as we are subclassing all editable objects to gain validation behaviors, which is exactly what we don't want for readonly objects. Thanks for answering though.
Andy
Subclassing objects to gain validation behavior smells to high heaven.
epitka